feat: merge upstream develop
This commit is contained in:
commit
8ad399a4aa
@ -28,6 +28,9 @@ import com.alibaba.nacos.api.utils.StringUtils;
|
|||||||
public class NamingUtils {
|
public class NamingUtils {
|
||||||
|
|
||||||
public static String getGroupedName(final String serviceName, final String groupName) {
|
public static String getGroupedName(final String serviceName, final String groupName) {
|
||||||
|
if (StringUtils.isBlank(serviceName)) {
|
||||||
|
throw new IllegalArgumentException("Param 'serviceName' is illegal, serviceName is blank");
|
||||||
|
}
|
||||||
final String resultGroupedName = groupName + Constants.SERVICE_INFO_SPLITER + serviceName;
|
final String resultGroupedName = groupName + Constants.SERVICE_INFO_SPLITER + serviceName;
|
||||||
return resultGroupedName.intern();
|
return resultGroupedName.intern();
|
||||||
}
|
}
|
||||||
|
@ -1,16 +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.
|
|
||||||
#
|
|
||||||
version=${project.version}
|
|
@ -40,6 +40,10 @@
|
|||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>nacos-common</artifactId>
|
<artifactId>nacos-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>nacos-sys</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.auth.common;
|
package com.alibaba.nacos.auth.common;
|
||||||
|
|
||||||
import com.alibaba.nacos.auth.common.env.ReloadableConfigs;
|
|
||||||
import com.alibaba.nacos.common.JustForTest;
|
import com.alibaba.nacos.common.JustForTest;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import io.jsonwebtoken.io.Decoders;
|
import io.jsonwebtoken.io.Decoders;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@ -40,9 +39,6 @@ public class AuthConfigs {
|
|||||||
@JustForTest
|
@JustForTest
|
||||||
private static Boolean cachingEnabled = null;
|
private static Boolean cachingEnabled = null;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ReloadableConfigs reloadableConfigs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* secret key.
|
* secret key.
|
||||||
*/
|
*/
|
||||||
@ -93,7 +89,7 @@ public class AuthConfigs {
|
|||||||
return BooleanUtils.toBoolean(enabled);
|
return BooleanUtils.toBoolean(enabled);
|
||||||
}
|
}
|
||||||
return BooleanUtils
|
return BooleanUtils
|
||||||
.toBoolean(reloadableConfigs.getProperties().getProperty("nacos.core.auth.enabled", "false"));
|
.toBoolean(ApplicationUtils.getProperty("nacos.core.auth.enabled", "false"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,7 +102,7 @@ public class AuthConfigs {
|
|||||||
return cachingEnabled;
|
return cachingEnabled;
|
||||||
}
|
}
|
||||||
return BooleanUtils
|
return BooleanUtils
|
||||||
.toBoolean(reloadableConfigs.getProperties().getProperty("nacos.core.auth.caching.enabled", "true"));
|
.toBoolean(ApplicationUtils.getProperty("nacos.core.auth.caching.enabled", "true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@JustForTest
|
@JustForTest
|
||||||
|
@ -1,75 +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.auth.common.env;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reload application.properties.
|
|
||||||
*
|
|
||||||
* @author nkorange
|
|
||||||
* @author mai.jh
|
|
||||||
* @since 1.2.0
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class ReloadableConfigs {
|
|
||||||
|
|
||||||
private static final String FILE_PREFIX = "file:";
|
|
||||||
|
|
||||||
private Properties properties;
|
|
||||||
|
|
||||||
@Value("${spring.config.location:}")
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Periodically load configuration file information.
|
|
||||||
*
|
|
||||||
* @throws IOException IOException
|
|
||||||
*/
|
|
||||||
@Scheduled(fixedRate = 5000)
|
|
||||||
public void reload() throws IOException {
|
|
||||||
final Properties properties = new Properties();
|
|
||||||
InputStream inputStream = null;
|
|
||||||
if (StringUtils.isNotBlank(path) && path.contains(FILE_PREFIX)) {
|
|
||||||
String[] paths = path.split(",");
|
|
||||||
path = paths[paths.length - 1].substring(FILE_PREFIX.length());
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
inputStream = new FileInputStream(new File(path + "application.properties"));
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
if (inputStream == null) {
|
|
||||||
inputStream = getClass().getResourceAsStream("/application.properties");
|
|
||||||
}
|
|
||||||
properties.load(inputStream);
|
|
||||||
inputStream.close();
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Properties getProperties() {
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,7 +32,6 @@ import com.alibaba.nacos.client.utils.ParamUtil;
|
|||||||
import com.alibaba.nacos.client.utils.TenantUtil;
|
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||||
import com.alibaba.nacos.common.http.HttpRestResult;
|
import com.alibaba.nacos.common.http.HttpRestResult;
|
||||||
import com.alibaba.nacos.common.lifecycle.Closeable;
|
import com.alibaba.nacos.common.lifecycle.Closeable;
|
||||||
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
|
|
||||||
import com.alibaba.nacos.common.utils.ConvertUtils;
|
import com.alibaba.nacos.common.utils.ConvertUtils;
|
||||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
@ -166,7 +165,6 @@ public class ClientWorker implements Closeable {
|
|||||||
copy.remove(groupKey);
|
copy.remove(groupKey);
|
||||||
cacheMap.set(copy);
|
cacheMap.set(copy);
|
||||||
}
|
}
|
||||||
reMakeCacheDataTaskId();
|
|
||||||
LOGGER.info("[{}] [unsubscribe] {}", this.agent.getName(), groupKey);
|
LOGGER.info("[{}] [unsubscribe] {}", this.agent.getName(), groupKey);
|
||||||
|
|
||||||
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
|
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
|
||||||
@ -179,38 +177,11 @@ public class ClientWorker implements Closeable {
|
|||||||
copy.remove(groupKey);
|
copy.remove(groupKey);
|
||||||
cacheMap.set(copy);
|
cacheMap.set(copy);
|
||||||
}
|
}
|
||||||
reMakeCacheDataTaskId();
|
|
||||||
LOGGER.info("[{}] [unsubscribe] {}", agent.getName(), groupKey);
|
LOGGER.info("[{}] [unsubscribe] {}", agent.getName(), groupKey);
|
||||||
|
|
||||||
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
|
MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remake cacheData taskId.
|
|
||||||
*/
|
|
||||||
private void reMakeCacheDataTaskId() {
|
|
||||||
int listenerSize = cacheMap.get().size();
|
|
||||||
int remakeTaskId = (int) Math.ceil(listenerSize / ParamUtil.getPerTaskConfigSize());
|
|
||||||
if (remakeTaskId < (int) currentLongingTaskCount) {
|
|
||||||
for (int i = 0; i < remakeTaskId; i++) {
|
|
||||||
int count = 0;
|
|
||||||
for (String key : cacheMap.get().keySet()) {
|
|
||||||
if (count == ParamUtil.getPerTaskConfigSize()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
CacheData cacheData = cacheMap.get().get(key);
|
|
||||||
cacheData.setTaskId(i);
|
|
||||||
synchronized (cacheMap) {
|
|
||||||
Map<String, CacheData> copy = new HashMap<String, CacheData>(this.cacheMap.get());
|
|
||||||
copy.put(key, cacheData);
|
|
||||||
cacheMap.set(copy);
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add cache data if absent.
|
* Add cache data if absent.
|
||||||
*
|
*
|
||||||
@ -277,8 +248,6 @@ public class ClientWorker implements Closeable {
|
|||||||
cache.setInitializing(true);
|
cache.setInitializing(true);
|
||||||
} else {
|
} else {
|
||||||
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
|
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
|
||||||
int taskId = cacheMap.get().size() / (int) ParamUtil.getPerTaskConfigSize();
|
|
||||||
cache.setTaskId(taskId);
|
|
||||||
// fix issue # 1317
|
// fix issue # 1317
|
||||||
if (enableRemoteSyncConfig) {
|
if (enableRemoteSyncConfig) {
|
||||||
String[] ct = getServerConfig(dataId, group, tenant, 3000L);
|
String[] ct = getServerConfig(dataId, group, tenant, 3000L);
|
||||||
@ -425,17 +394,12 @@ public class ClientWorker implements Closeable {
|
|||||||
int longingTaskCount = (int) Math.ceil(listenerSize / ParamUtil.getPerTaskConfigSize());
|
int longingTaskCount = (int) Math.ceil(listenerSize / ParamUtil.getPerTaskConfigSize());
|
||||||
if (longingTaskCount > currentLongingTaskCount) {
|
if (longingTaskCount > currentLongingTaskCount) {
|
||||||
for (int i = (int) currentLongingTaskCount; i < longingTaskCount; i++) {
|
for (int i = (int) currentLongingTaskCount; i < longingTaskCount; i++) {
|
||||||
taskIdSet.add(i);
|
|
||||||
// The task list is no order.So it maybe has issues when changing.
|
// The task list is no order.So it maybe has issues when changing.
|
||||||
executorService.execute(new LongPollingRunnable(i));
|
executorService.execute(new LongPollingRunnable(i));
|
||||||
}
|
}
|
||||||
} else if (longingTaskCount < currentLongingTaskCount) {
|
|
||||||
for (int i = longingTaskCount; i < (int) currentLongingTaskCount; i++) {
|
|
||||||
taskIdSet.remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentLongingTaskCount = longingTaskCount;
|
currentLongingTaskCount = longingTaskCount;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the dataId list from server.
|
* Fetch the dataId list from server.
|
||||||
@ -692,9 +656,7 @@ public class ClientWorker implements Closeable {
|
|||||||
}
|
}
|
||||||
inInitializingCacheList.clear();
|
inInitializingCacheList.clear();
|
||||||
|
|
||||||
if (taskIdSet.contains(taskId)) {
|
|
||||||
executorService.execute(this);
|
executorService.execute(this);
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
||||||
@ -723,11 +685,6 @@ public class ClientWorker implements Closeable {
|
|||||||
private final AtomicReference<Map<String, CacheData>> cacheMap = new AtomicReference<Map<String, CacheData>>(
|
private final AtomicReference<Map<String, CacheData>> cacheMap = new AtomicReference<Map<String, CacheData>>(
|
||||||
new HashMap<String, CacheData>());
|
new HashMap<String, CacheData>());
|
||||||
|
|
||||||
/**
|
|
||||||
* Store the running taskId.
|
|
||||||
*/
|
|
||||||
private final ConcurrentHashSet<Integer> taskIdSet = new ConcurrentHashSet<Integer>();
|
|
||||||
|
|
||||||
private final HttpAgent agent;
|
private final HttpAgent agent;
|
||||||
|
|
||||||
private final ConfigFilterChainManager configFilterChainManager;
|
private final ConfigFilterChainManager configFilterChainManager;
|
||||||
|
@ -143,11 +143,12 @@ public class ConcurrentDiskUtil {
|
|||||||
}
|
}
|
||||||
} while (null == lock);
|
} while (null == lock);
|
||||||
|
|
||||||
ByteBuffer sendBuffer = ByteBuffer.wrap(content.getBytes(charsetName));
|
byte[] contentBytes = content.getBytes(charsetName);
|
||||||
|
ByteBuffer sendBuffer = ByteBuffer.wrap(contentBytes);
|
||||||
while (sendBuffer.hasRemaining()) {
|
while (sendBuffer.hasRemaining()) {
|
||||||
channel.write(sendBuffer);
|
channel.write(sendBuffer);
|
||||||
}
|
}
|
||||||
channel.truncate(content.length());
|
channel.truncate(contentBytes.length);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new IOException("file not exist");
|
throw new IOException("file not exist");
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -107,6 +107,9 @@ public class PushReceiver implements Runnable, Closeable {
|
|||||||
udpSocket.send(new DatagramPacket(ack.getBytes(UTF_8), ack.getBytes(UTF_8).length,
|
udpSocket.send(new DatagramPacket(ack.getBytes(UTF_8), ack.getBytes(UTF_8).length,
|
||||||
packet.getSocketAddress()));
|
packet.getSocketAddress()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (closed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
NAMING_LOGGER.error("[NA] error while receiving push data", e);
|
NAMING_LOGGER.error("[NA] error while receiving push data", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,9 @@ import com.alibaba.nacos.api.PropertyKeyConst;
|
|||||||
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
import com.alibaba.nacos.api.SystemPropertyKeyConst;
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
|
import com.alibaba.nacos.common.utils.VersionUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -80,19 +80,7 @@ public class ParamUtil {
|
|||||||
}
|
}
|
||||||
LOGGER.info("[settings] [http-client] connect timeout:{}", connectTimeout);
|
LOGGER.info("[settings] [http-client] connect timeout:{}", connectTimeout);
|
||||||
|
|
||||||
try {
|
clientVersion = VersionUtils.version;
|
||||||
InputStream in = ValidatorUtils.class.getClassLoader().getResourceAsStream("application.properties");
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.load(in);
|
|
||||||
String val = null;
|
|
||||||
val = props.getProperty("version");
|
|
||||||
if (val != null) {
|
|
||||||
clientVersion = val;
|
|
||||||
}
|
|
||||||
LOGGER.info("NACOS_CLIENT_VERSION: {}", clientVersion);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("[500] read application.properties", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
perTaskConfigSize = Double.valueOf(System.getProperty("PER_TASK_CONFIG_SIZE", "3000"));
|
perTaskConfigSize = Double.valueOf(System.getProperty("PER_TASK_CONFIG_SIZE", "3000"));
|
||||||
|
@ -1,16 +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.
|
|
||||||
#
|
|
||||||
version=${project.version}
|
|
@ -1,132 +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.client.config.listener.impl;
|
|
||||||
|
|
||||||
import com.alibaba.nacos.api.config.listener.Listener;
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
|
||||||
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
|
|
||||||
import com.alibaba.nacos.client.config.http.MetricsHttpAgent;
|
|
||||||
import com.alibaba.nacos.client.config.impl.ClientWorker;
|
|
||||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
public class ClientWorkerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
ScheduledExecutorService scheduledExecutorService;
|
|
||||||
|
|
||||||
private ClientWorker clientWorker;
|
|
||||||
|
|
||||||
private List<Listener> listeners;
|
|
||||||
|
|
||||||
private final String dataId = "data";
|
|
||||||
|
|
||||||
private final String group = "group";
|
|
||||||
|
|
||||||
private final String currentLongingTaskCount = "currentLongingTaskCount";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void init() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
clientWorker = new ClientWorker(mock(MetricsHttpAgent.class), mock(ConfigFilterChainManager.class),
|
|
||||||
mock(Properties.class));
|
|
||||||
try {
|
|
||||||
Field executorServiceField = clientWorker.getClass().getDeclaredField("executorService");
|
|
||||||
executorServiceField.setAccessible(true);
|
|
||||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
modifiersField.setInt(executorServiceField, executorServiceField.getModifiers() & ~Modifier.FINAL);
|
|
||||||
executorServiceField.set(clientWorker, scheduledExecutorService);
|
|
||||||
Listener listener = new Listener() {
|
|
||||||
@Override
|
|
||||||
public Executor getExecutor() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveConfigInfo(String configInfo) {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
listeners = Arrays.asList(listener);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddLongPollNumberThreads() {
|
|
||||||
try {
|
|
||||||
for (int i = 0; i < ParamUtil.getPerTaskConfigSize(); i++) {
|
|
||||||
clientWorker.addTenantListeners(dataId + i, group, listeners);
|
|
||||||
}
|
|
||||||
Field currentLongingTaskCountField = clientWorker.getClass().getDeclaredField(currentLongingTaskCount);
|
|
||||||
currentLongingTaskCountField.setAccessible(true);
|
|
||||||
Assert.assertEquals(currentLongingTaskCount, (int) currentLongingTaskCountField.getDouble(clientWorker), 1);
|
|
||||||
for (int i = (int) ParamUtil.getPerTaskConfigSize(); i < ParamUtil.getPerTaskConfigSize() * 2; i++) {
|
|
||||||
clientWorker.addTenantListeners(dataId + i, group, listeners);
|
|
||||||
}
|
|
||||||
Assert.assertEquals(currentLongingTaskCount, (int) currentLongingTaskCountField.getDouble(clientWorker), 2);
|
|
||||||
} catch (NacosException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReduceLongPollNumberThreads() {
|
|
||||||
try {
|
|
||||||
for (int i = 0; i < ParamUtil.getPerTaskConfigSize() * 3; i++) {
|
|
||||||
clientWorker.addTenantListeners(dataId + i, group, listeners);
|
|
||||||
}
|
|
||||||
Field currentLongingTaskCountField = clientWorker.getClass().getDeclaredField(currentLongingTaskCount);
|
|
||||||
currentLongingTaskCountField.setAccessible(true);
|
|
||||||
Assert.assertEquals(currentLongingTaskCount, (int) currentLongingTaskCountField.getDouble(clientWorker), 3);
|
|
||||||
|
|
||||||
for (int i = (int) ParamUtil.getPerTaskConfigSize(); i < ParamUtil.getPerTaskConfigSize() * 2; i++) {
|
|
||||||
clientWorker.removeTenantListener(dataId + i, group, listeners.get(0));
|
|
||||||
}
|
|
||||||
Assert.assertEquals(currentLongingTaskCount, (int) currentLongingTaskCountField.getDouble(clientWorker), 2);
|
|
||||||
} catch (NacosException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -47,6 +47,7 @@ public class DiskCacheTest {
|
|||||||
instance.setIp("1.1.1.1");
|
instance.setIp("1.1.1.1");
|
||||||
instance.setPort(1234);
|
instance.setPort(1234);
|
||||||
instance.setServiceName("testName");
|
instance.setServiceName("testName");
|
||||||
|
instance.addMetadata("chinese", "中文");
|
||||||
serviceInfo.setHosts(Collections.singletonList(instance));
|
serviceInfo.setHosts(Collections.singletonList(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,9 +88,10 @@ public class DiskCacheTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertInstance(Instance actual, Instance expected) {
|
private void assertInstance(Instance actual, Instance expected) {
|
||||||
assertEquals(actual.getServiceName(), actual.getServiceName());
|
assertEquals(actual.getServiceName(), expected.getServiceName());
|
||||||
assertEquals(actual.getClusterName(), actual.getClusterName());
|
assertEquals(actual.getClusterName(), expected.getClusterName());
|
||||||
assertEquals(actual.getIp(), actual.getIp());
|
assertEquals(actual.getIp(), expected.getIp());
|
||||||
assertEquals(actual.getPort(), actual.getPort());
|
assertEquals(actual.getPort(), expected.getPort());
|
||||||
|
assertEquals(actual.getMetadata(), expected.getMetadata());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,15 @@ public abstract class AbstractApacheHttpClientFactory extends AbstractHttpClient
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final NacosRestTemplate createNacosRestTemplate() {
|
public final NacosRestTemplate createNacosRestTemplate() {
|
||||||
|
final HttpClientConfig originalRequestConfig = buildHttpClientConfig();
|
||||||
final RequestConfig requestConfig = getRequestConfig();
|
final RequestConfig requestConfig = getRequestConfig();
|
||||||
return new NacosRestTemplate(assignLogger(),
|
return new NacosRestTemplate(assignLogger(), new DefaultHttpClientRequest(
|
||||||
new DefaultHttpClientRequest(HttpClients.custom().setDefaultRequestConfig(requestConfig).build()));
|
HttpClients.custom().setDefaultRequestConfig(requestConfig)
|
||||||
|
.setUserAgent(originalRequestConfig.getUserAgent())
|
||||||
|
.setMaxConnTotal(originalRequestConfig.getMaxConnTotal())
|
||||||
|
.setMaxConnPerRoute(originalRequestConfig.getMaxConnPerRoute())
|
||||||
|
.setConnectionTimeToLive(originalRequestConfig.getConnTimeToLive(),
|
||||||
|
originalRequestConfig.getConnTimeToLiveTimeUnit()).build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,15 +67,20 @@ public abstract class AbstractHttpClientFactory implements HttpClientFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NacosAsyncRestTemplate createNacosAsyncRestTemplate() {
|
public NacosAsyncRestTemplate createNacosAsyncRestTemplate() {
|
||||||
RequestConfig requestConfig = getRequestConfig();
|
final HttpClientConfig originalRequestConfig = buildHttpClientConfig();
|
||||||
|
final RequestConfig requestConfig = getRequestConfig();
|
||||||
return new NacosAsyncRestTemplate(assignLogger(), new DefaultAsyncHttpClientRequest(
|
return new NacosAsyncRestTemplate(assignLogger(), new DefaultAsyncHttpClientRequest(
|
||||||
HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).build()));
|
HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig)
|
||||||
|
.setMaxConnTotal(originalRequestConfig.getMaxConnTotal())
|
||||||
|
.setMaxConnPerRoute(originalRequestConfig.getMaxConnPerRoute())
|
||||||
|
.setUserAgent(originalRequestConfig.getUserAgent()).build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RequestConfig getRequestConfig() {
|
protected RequestConfig getRequestConfig() {
|
||||||
HttpClientConfig httpClientConfig = buildHttpClientConfig();
|
HttpClientConfig httpClientConfig = buildHttpClientConfig();
|
||||||
return RequestConfig.custom().setConnectTimeout(httpClientConfig.getConTimeOutMillis())
|
return RequestConfig.custom().setConnectTimeout(httpClientConfig.getConTimeOutMillis())
|
||||||
.setSocketTimeout(httpClientConfig.getReadTimeOutMillis())
|
.setSocketTimeout(httpClientConfig.getReadTimeOutMillis())
|
||||||
|
.setConnectionRequestTimeout(httpClientConfig.getConnectionRequestTimeout())
|
||||||
.setMaxRedirects(httpClientConfig.getMaxRedirects()).build();
|
.setMaxRedirects(httpClientConfig.getMaxRedirects()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.common.http;
|
package com.alibaba.nacos.common.http;
|
||||||
|
|
||||||
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
|
||||||
import com.alibaba.nacos.common.http.handler.ResponseHandler;
|
import com.alibaba.nacos.common.http.handler.ResponseHandler;
|
||||||
import com.alibaba.nacos.common.http.param.Header;
|
import com.alibaba.nacos.common.http.param.Header;
|
||||||
import com.alibaba.nacos.common.http.param.Query;
|
import com.alibaba.nacos.common.http.param.Query;
|
||||||
@ -103,7 +102,7 @@ public abstract class BaseHttpClient {
|
|||||||
final BaseHttpMethod httpMethod = BaseHttpMethod.sourceOf(method);
|
final BaseHttpMethod httpMethod = BaseHttpMethod.sourceOf(method);
|
||||||
final HttpRequestBase httpRequestBase = httpMethod.init(url);
|
final HttpRequestBase httpRequestBase = httpMethod.init(url);
|
||||||
HttpUtils.initRequestHeader(httpRequestBase, header);
|
HttpUtils.initRequestHeader(httpRequestBase, header);
|
||||||
HttpUtils.initRequestEntity(httpRequestBase, body, header.getValue(HttpHeaderConsts.CONTENT_TYPE));
|
HttpUtils.initRequestEntity(httpRequestBase, body, header);
|
||||||
return httpRequestBase;
|
return httpRequestBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,16 @@ public enum BaseHttpMethod {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete Large request.
|
||||||
|
*/
|
||||||
|
DELETE_LARGE(HttpMethod.DELETE_LARGE) {
|
||||||
|
@Override
|
||||||
|
protected HttpRequestBase createRequest(String url) {
|
||||||
|
return new HttpDeleteWithEntity(url);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* head request.
|
* head request.
|
||||||
*/
|
*/
|
||||||
@ -155,6 +165,10 @@ public enum BaseHttpMethod {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get Large implemented.
|
* get Large implemented.
|
||||||
|
* <p>
|
||||||
|
* Mainly used for GET request parameters are relatively large, can not be placed on the URL, so it needs to be
|
||||||
|
* placed in the body.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public static class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {
|
public static class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {
|
||||||
|
|
||||||
@ -171,4 +185,26 @@ public enum BaseHttpMethod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete Large implemented.
|
||||||
|
* <p>
|
||||||
|
* Mainly used for DELETE request parameters are relatively large, can not be placed on the URL, so it needs to be
|
||||||
|
* placed in the body.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public static class HttpDeleteWithEntity extends HttpEntityEnclosingRequestBase {
|
||||||
|
|
||||||
|
public static final String METHOD_NAME = "DELETE";
|
||||||
|
|
||||||
|
public HttpDeleteWithEntity(String url) {
|
||||||
|
super();
|
||||||
|
setURI(URI.create(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethod() {
|
||||||
|
return METHOD_NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.common.http;
|
package com.alibaba.nacos.common.http;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http client config build.
|
* http client config build.
|
||||||
*
|
*
|
||||||
@ -23,16 +25,62 @@ package com.alibaba.nacos.common.http;
|
|||||||
*/
|
*/
|
||||||
public class HttpClientConfig {
|
public class HttpClientConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* connect time out.
|
||||||
|
*/
|
||||||
private final int conTimeOutMillis;
|
private final int conTimeOutMillis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read time out.
|
||||||
|
*/
|
||||||
private final int readTimeOutMillis;
|
private final int readTimeOutMillis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* connTimeToLive.
|
||||||
|
*/
|
||||||
|
private final long connTimeToLive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* connTimeToLiveTimeUnit.
|
||||||
|
*/
|
||||||
|
private final TimeUnit connTimeToLiveTimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* connectionRequestTimeout.
|
||||||
|
*/
|
||||||
|
private final int connectionRequestTimeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* max redirect.
|
||||||
|
*/
|
||||||
private final int maxRedirects;
|
private final int maxRedirects;
|
||||||
|
|
||||||
public HttpClientConfig(int conTimeOutMillis, int readTimeOutMillis, int maxRedirects) {
|
/**
|
||||||
|
* max connect total.
|
||||||
|
*/
|
||||||
|
private final int maxConnTotal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assigns maximum connection per route value.
|
||||||
|
*/
|
||||||
|
private final int maxConnPerRoute;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user agent.
|
||||||
|
*/
|
||||||
|
private final String userAgent;
|
||||||
|
|
||||||
|
public HttpClientConfig(int conTimeOutMillis, int readTimeOutMillis, long connTimeToLive, TimeUnit timeUnit,
|
||||||
|
int connectionRequestTimeout, int maxRedirects, int maxConnTotal, int maxConnPerRoute, String userAgent) {
|
||||||
this.conTimeOutMillis = conTimeOutMillis;
|
this.conTimeOutMillis = conTimeOutMillis;
|
||||||
this.readTimeOutMillis = readTimeOutMillis;
|
this.readTimeOutMillis = readTimeOutMillis;
|
||||||
|
this.connTimeToLive = connTimeToLive;
|
||||||
|
this.connTimeToLiveTimeUnit = timeUnit;
|
||||||
|
this.connectionRequestTimeout = connectionRequestTimeout;
|
||||||
this.maxRedirects = maxRedirects;
|
this.maxRedirects = maxRedirects;
|
||||||
|
this.maxConnTotal = maxConnTotal;
|
||||||
|
this.maxConnPerRoute = maxConnPerRoute;
|
||||||
|
this.userAgent = userAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getConTimeOutMillis() {
|
public int getConTimeOutMillis() {
|
||||||
@ -43,10 +91,34 @@ public class HttpClientConfig {
|
|||||||
return readTimeOutMillis;
|
return readTimeOutMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getConnTimeToLive() {
|
||||||
|
return connTimeToLive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeUnit getConnTimeToLiveTimeUnit() {
|
||||||
|
return connTimeToLiveTimeUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConnectionRequestTimeout() {
|
||||||
|
return connectionRequestTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMaxRedirects() {
|
public int getMaxRedirects() {
|
||||||
return maxRedirects;
|
return maxRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxConnTotal() {
|
||||||
|
return maxConnTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxConnPerRoute() {
|
||||||
|
return maxConnPerRoute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserAgent() {
|
||||||
|
return userAgent;
|
||||||
|
}
|
||||||
|
|
||||||
public static HttpClientConfigBuilder builder() {
|
public static HttpClientConfigBuilder builder() {
|
||||||
return new HttpClientConfigBuilder();
|
return new HttpClientConfigBuilder();
|
||||||
}
|
}
|
||||||
@ -57,8 +129,20 @@ public class HttpClientConfig {
|
|||||||
|
|
||||||
private int readTimeOutMillis = -1;
|
private int readTimeOutMillis = -1;
|
||||||
|
|
||||||
|
private long connTimeToLive = -1;
|
||||||
|
|
||||||
|
private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
|
private int connectionRequestTimeout = -1;
|
||||||
|
|
||||||
private int maxRedirects = 50;
|
private int maxRedirects = 50;
|
||||||
|
|
||||||
|
private int maxConnTotal = 0;
|
||||||
|
|
||||||
|
private int maxConnPerRoute = 0;
|
||||||
|
|
||||||
|
private String userAgent;
|
||||||
|
|
||||||
public HttpClientConfigBuilder setConTimeOutMillis(int conTimeOutMillis) {
|
public HttpClientConfigBuilder setConTimeOutMillis(int conTimeOutMillis) {
|
||||||
this.conTimeOutMillis = conTimeOutMillis;
|
this.conTimeOutMillis = conTimeOutMillis;
|
||||||
return this;
|
return this;
|
||||||
@ -69,13 +153,40 @@ public class HttpClientConfig {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpClientConfigBuilder setConnectionTimeToLive(long connTimeToLive, TimeUnit connTimeToLiveTimeUnit) {
|
||||||
|
this.connTimeToLive = connTimeToLive;
|
||||||
|
this.connTimeToLiveTimeUnit = connTimeToLiveTimeUnit;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpClientConfigBuilder setConnectionRequestTimeout(int connectionRequestTimeout) {
|
||||||
|
this.connectionRequestTimeout = connectionRequestTimeout;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public HttpClientConfigBuilder setMaxRedirects(int maxRedirects) {
|
public HttpClientConfigBuilder setMaxRedirects(int maxRedirects) {
|
||||||
this.maxRedirects = maxRedirects;
|
this.maxRedirects = maxRedirects;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpClientConfigBuilder setMaxConnTotal(int maxConnTotal) {
|
||||||
|
this.maxConnTotal = maxConnTotal;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpClientConfigBuilder setMaxConnPerRoute(int maxConnPerRoute) {
|
||||||
|
this.maxConnPerRoute = maxConnPerRoute;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpClientConfigBuilder setUserAgent(String userAgent) {
|
||||||
|
this.userAgent = userAgent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public HttpClientConfig build() {
|
public HttpClientConfig build() {
|
||||||
return new HttpClientConfig(conTimeOutMillis, readTimeOutMillis, maxRedirects);
|
return new HttpClientConfig(conTimeOutMillis, readTimeOutMillis, connTimeToLive, connTimeToLiveTimeUnit,
|
||||||
|
connectionRequestTimeout, maxRedirects, maxConnTotal, maxConnPerRoute, userAgent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,18 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.common.http;
|
package com.alibaba.nacos.common.http;
|
||||||
|
|
||||||
import com.alibaba.nacos.common.http.handler.RequestHandler;
|
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
||||||
import com.alibaba.nacos.common.http.param.Header;
|
import com.alibaba.nacos.common.http.param.Header;
|
||||||
|
import com.alibaba.nacos.common.http.param.MediaType;
|
||||||
import com.alibaba.nacos.common.http.param.Query;
|
import com.alibaba.nacos.common.http.param.Query;
|
||||||
|
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpEntityEnclosingRequest;
|
import org.apache.http.HttpEntityEnclosingRequest;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
import org.apache.http.client.methods.HttpRequestBase;
|
import org.apache.http.client.methods.HttpRequestBase;
|
||||||
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
@ -70,17 +73,23 @@ public final class HttpUtils {
|
|||||||
*
|
*
|
||||||
* @param requestBase requestBase {@link HttpRequestBase}
|
* @param requestBase requestBase {@link HttpRequestBase}
|
||||||
* @param body body
|
* @param body body
|
||||||
* @param mediaType mediaType {@link ContentType}
|
* @param header request header
|
||||||
* @throws Exception exception
|
* @throws Exception exception
|
||||||
*/
|
*/
|
||||||
public static void initRequestEntity(HttpRequestBase requestBase, Object body, String mediaType) throws Exception {
|
public static void initRequestEntity(HttpRequestBase requestBase, Object body, Header header) throws Exception {
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestBase instanceof HttpEntityEnclosingRequest) {
|
if (requestBase instanceof HttpEntityEnclosingRequest) {
|
||||||
HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) requestBase;
|
HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) requestBase;
|
||||||
ContentType contentType = ContentType.create(mediaType);
|
MediaType mediaType = MediaType.valueOf(header.getValue(HttpHeaderConsts.CONTENT_TYPE));
|
||||||
StringEntity entity = new StringEntity(RequestHandler.parse(body), contentType);
|
ContentType contentType = ContentType.create(mediaType.getType(), mediaType.getCharset());
|
||||||
|
HttpEntity entity;
|
||||||
|
if (body instanceof byte[]) {
|
||||||
|
entity = new ByteArrayEntity((byte[]) body, contentType);
|
||||||
|
} else {
|
||||||
|
entity = new StringEntity(body instanceof String ? (String) body : JacksonUtils.toJson(body), contentType);
|
||||||
|
}
|
||||||
request.setEntity(entity);
|
request.setEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,27 @@ public class NacosAsyncRestTemplate extends AbstractNacosRestTemplate {
|
|||||||
execute(url, HttpMethod.DELETE, new RequestHttpEntity(header, query), responseType, callback);
|
execute(url, HttpMethod.DELETE, new RequestHttpEntity(header, query), responseType, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* async http delete large request, when the parameter exceeds the URL limit, you can use this method to put the
|
||||||
|
* parameter into the body pass.
|
||||||
|
*
|
||||||
|
* <p>{@code responseType} can be an RestResult or RestResult data {@code T} type
|
||||||
|
*
|
||||||
|
* <p>{@code callback} Result callback execution,
|
||||||
|
* if you need response headers, you can convert the received RestResult to HttpRestResult.
|
||||||
|
*
|
||||||
|
* @param url url
|
||||||
|
* @param header http header param
|
||||||
|
* @param body body
|
||||||
|
* @param responseType return type
|
||||||
|
* @param callback callback {@link Callback#onReceive(com.alibaba.nacos.common.model.RestResult)}
|
||||||
|
*/
|
||||||
|
public <T> void delete(String url, Header header, String body, Type responseType, Callback<T> callback) {
|
||||||
|
execute(url, HttpMethod.DELETE_LARGE,
|
||||||
|
new RequestHttpEntity(header.setContentType(MediaType.APPLICATION_JSON), Query.EMPTY, body),
|
||||||
|
responseType, callback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* async http put Create a new resource by PUTting the given body to http request.
|
* async http put Create a new resource by PUTting the given body to http request.
|
||||||
*
|
*
|
||||||
|
@ -427,6 +427,26 @@ public class NacosRestTemplate extends AbstractNacosRestTemplate {
|
|||||||
return execute(url, httpMethod, requestHttpEntity, responseType);
|
return execute(url, httpMethod, requestHttpEntity, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns
|
||||||
|
* the response as {@link HttpRestResult}.
|
||||||
|
*
|
||||||
|
* @param url url
|
||||||
|
* @param config HttpClientConfig
|
||||||
|
* @param header http header param
|
||||||
|
* @param query http query param
|
||||||
|
* @param body http body param
|
||||||
|
* @param httpMethod http method
|
||||||
|
* @param responseType return type
|
||||||
|
* @return {@link HttpRestResult}
|
||||||
|
* @throws Exception ex
|
||||||
|
*/
|
||||||
|
public <T> HttpRestResult<T> exchange(String url, HttpClientConfig config, Header header, Query query,
|
||||||
|
Object body, String httpMethod, Type responseType) throws Exception {
|
||||||
|
RequestHttpEntity requestHttpEntity = new RequestHttpEntity(config, header, query, body);
|
||||||
|
return execute(url, httpMethod, requestHttpEntity, responseType);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the request interceptors that this accessor should use.
|
* Set the request interceptors that this accessor should use.
|
||||||
*
|
*
|
||||||
|
@ -65,7 +65,7 @@ public class DefaultHttpClientRequest implements HttpClientRequest {
|
|||||||
&& requestHttpEntity.getBody() instanceof Map) {
|
&& requestHttpEntity.getBody() instanceof Map) {
|
||||||
HttpUtils.initRequestFromEntity(httpRequestBase, (Map<String, String>) requestHttpEntity.getBody(), headers.getCharset());
|
HttpUtils.initRequestFromEntity(httpRequestBase, (Map<String, String>) requestHttpEntity.getBody(), headers.getCharset());
|
||||||
} else {
|
} else {
|
||||||
HttpUtils.initRequestEntity(httpRequestBase, requestHttpEntity.getBody(), headers.getValue(HttpHeaderConsts.CONTENT_TYPE));
|
HttpUtils.initRequestEntity(httpRequestBase, requestHttpEntity.getBody(), headers);
|
||||||
}
|
}
|
||||||
replaceDefaultConfig(httpRequestBase, requestHttpEntity.getHttpClientConfig());
|
replaceDefaultConfig(httpRequestBase, requestHttpEntity.getHttpClientConfig());
|
||||||
return httpRequestBase;
|
return httpRequestBase;
|
||||||
|
@ -90,7 +90,7 @@ public class JdkHttpClientRequest implements HttpClientRequest {
|
|||||||
conn.setConnectTimeout(this.httpClientConfig.getConTimeOutMillis());
|
conn.setConnectTimeout(this.httpClientConfig.getConTimeOutMillis());
|
||||||
conn.setReadTimeout(this.httpClientConfig.getReadTimeOutMillis());
|
conn.setReadTimeout(this.httpClientConfig.getReadTimeOutMillis());
|
||||||
conn.setRequestMethod(httpMethod);
|
conn.setRequestMethod(httpMethod);
|
||||||
if (body != null) {
|
if (body != null && !"".equals(body)) {
|
||||||
String contentType = headers.getValue(HttpHeaderConsts.CONTENT_TYPE);
|
String contentType = headers.getValue(HttpHeaderConsts.CONTENT_TYPE);
|
||||||
String bodyStr = JacksonUtils.toJson(body);
|
String bodyStr = JacksonUtils.toJson(body);
|
||||||
if (MediaType.APPLICATION_FORM_URLENCODED.equals(contentType)) {
|
if (MediaType.APPLICATION_FORM_URLENCODED.equals(contentType)) {
|
||||||
|
@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.common.http.client.response;
|
package com.alibaba.nacos.common.http.client.response;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
||||||
import com.alibaba.nacos.common.http.param.Header;
|
import com.alibaba.nacos.common.http.param.Header;
|
||||||
import com.alibaba.nacos.common.utils.IoUtils;
|
import com.alibaba.nacos.common.utils.IoUtils;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@ -36,6 +38,8 @@ public class JdkHttpClientResponse implements HttpClientResponse {
|
|||||||
|
|
||||||
private Header responseHeader;
|
private Header responseHeader;
|
||||||
|
|
||||||
|
private static final String CONTENT_ENCODING = "gzip";
|
||||||
|
|
||||||
public JdkHttpClientResponse(HttpURLConnection conn) {
|
public JdkHttpClientResponse(HttpURLConnection conn) {
|
||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
}
|
}
|
||||||
@ -51,8 +55,18 @@ public class JdkHttpClientResponse implements HttpClientResponse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
|
Header headers = getHeaders();
|
||||||
InputStream errorStream = this.conn.getErrorStream();
|
InputStream errorStream = this.conn.getErrorStream();
|
||||||
this.responseStream = (errorStream != null ? errorStream : this.conn.getInputStream());
|
this.responseStream = (errorStream != null ? errorStream : this.conn.getInputStream());
|
||||||
|
String contentEncoding = headers.getValue(HttpHeaderConsts.CONTENT_ENCODING);
|
||||||
|
// Used to process http content_encoding, when content_encoding is GZIP, use GZIPInputStream
|
||||||
|
if (CONTENT_ENCODING.equals(contentEncoding)) {
|
||||||
|
byte[] bytes = IoUtils.tryDecompress(this.responseStream);
|
||||||
|
if (bytes == null) {
|
||||||
|
throw new IOException("decompress http response error");
|
||||||
|
}
|
||||||
|
return new ByteArrayInputStream(bytes);
|
||||||
|
}
|
||||||
return this.responseStream;
|
return this.responseStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package com.alibaba.nacos.common.http.param;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
||||||
|
import com.alibaba.nacos.common.utils.MapUtils;
|
||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -45,7 +46,6 @@ public class Header {
|
|||||||
addParam(HttpHeaderConsts.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
addParam(HttpHeaderConsts.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||||
addParam(HttpHeaderConsts.ACCEPT_CHARSET, "UTF-8");
|
addParam(HttpHeaderConsts.ACCEPT_CHARSET, "UTF-8");
|
||||||
addParam(HttpHeaderConsts.ACCEPT_ENCODING, "gzip");
|
addParam(HttpHeaderConsts.ACCEPT_ENCODING, "gzip");
|
||||||
addParam(HttpHeaderConsts.CONTENT_ENCODING, "gzip");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Header newInstance() {
|
public static Header newInstance() {
|
||||||
@ -130,10 +130,12 @@ public class Header {
|
|||||||
* @param params parameters
|
* @param params parameters
|
||||||
*/
|
*/
|
||||||
public void addAll(Map<String, String> params) {
|
public void addAll(Map<String, String> params) {
|
||||||
|
if (MapUtils.isNotEmpty(params)) {
|
||||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||||
addParam(entry.getKey(), entry.getValue());
|
addParam(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set original format response header.
|
* set original format response header.
|
||||||
@ -143,11 +145,13 @@ public class Header {
|
|||||||
* @param headers original response header
|
* @param headers original response header
|
||||||
*/
|
*/
|
||||||
public void setOriginalResponseHeader(Map<String, List<String>> headers) {
|
public void setOriginalResponseHeader(Map<String, List<String>> headers) {
|
||||||
|
if (MapUtils.isNotEmpty(headers)) {
|
||||||
this.originalResponseHeader.putAll(headers);
|
this.originalResponseHeader.putAll(headers);
|
||||||
for (Map.Entry<String, List<String>> entry : this.originalResponseHeader.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : this.originalResponseHeader.entrySet()) {
|
||||||
addParam(entry.getKey(), entry.getValue().get(0));
|
addParam(entry.getKey(), entry.getValue().get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get original format response header.
|
* get original format response header.
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.common.http.param;
|
package com.alibaba.nacos.common.http.param;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Http Media type.
|
* Http Media type.
|
||||||
*
|
*
|
||||||
@ -23,12 +26,9 @@ package com.alibaba.nacos.common.http.param;
|
|||||||
*/
|
*/
|
||||||
public final class MediaType {
|
public final class MediaType {
|
||||||
|
|
||||||
private MediaType() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String APPLICATION_ATOM_XML = "application/atom+xml";
|
public static final String APPLICATION_ATOM_XML = "application/atom+xml";
|
||||||
|
|
||||||
public static final String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
|
public static final String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||||
|
|
||||||
public static final String APPLICATION_OCTET_STREAM = "application/octet-stream";
|
public static final String APPLICATION_OCTET_STREAM = "application/octet-stream";
|
||||||
|
|
||||||
@ -36,14 +36,76 @@ public final class MediaType {
|
|||||||
|
|
||||||
public static final String APPLICATION_XHTML_XML = "application/xhtml+xml";
|
public static final String APPLICATION_XHTML_XML = "application/xhtml+xml";
|
||||||
|
|
||||||
public static final String APPLICATION_XML = "application/xml";
|
public static final String APPLICATION_XML = "application/xml;charset=UTF-8";
|
||||||
|
|
||||||
public static final String APPLICATION_JSON = "application/json";
|
public static final String APPLICATION_JSON = "application/json;charset=UTF-8";
|
||||||
|
|
||||||
public static final String MULTIPART_FORM_DATA = "multipart/form-data";
|
public static final String MULTIPART_FORM_DATA = "multipart/form-data;charset=UTF-8";
|
||||||
|
|
||||||
public static final String TEXT_HTML = "text/html";
|
public static final String TEXT_HTML = "text/html;charset=UTF-8";
|
||||||
|
|
||||||
public static final String TEXT_PLAIN = "text/plain";
|
public static final String TEXT_PLAIN = "text/plain;charset=UTF-8";
|
||||||
|
|
||||||
|
private MediaType(String type, String charset) {
|
||||||
|
this.type = type;
|
||||||
|
this.charset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* content type.
|
||||||
|
*/
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* content type charset.
|
||||||
|
*/
|
||||||
|
private final String charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the given String contentType into a {@code MediaType} object.
|
||||||
|
*
|
||||||
|
* @param contentType mediaType
|
||||||
|
* @return MediaType
|
||||||
|
*/
|
||||||
|
public static MediaType valueOf(String contentType) {
|
||||||
|
if (StringUtils.isEmpty(contentType)) {
|
||||||
|
throw new IllegalArgumentException("MediaType must not be empty");
|
||||||
|
}
|
||||||
|
String[] values = contentType.split(";");
|
||||||
|
String charset = Constants.ENCODE;
|
||||||
|
for (String value : values) {
|
||||||
|
if (value.startsWith("charset=")) {
|
||||||
|
charset = value.substring("charset=".length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new MediaType(values[0], charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the given contentType and charset to assemble into a {@code MediaType} object.
|
||||||
|
*
|
||||||
|
* @param contentType contentType
|
||||||
|
* @param charset charset
|
||||||
|
* @return MediaType
|
||||||
|
*/
|
||||||
|
public static MediaType valueOf(String contentType, String charset) {
|
||||||
|
if (StringUtils.isEmpty(contentType)) {
|
||||||
|
throw new IllegalArgumentException("MediaType must not be empty");
|
||||||
|
}
|
||||||
|
String[] values = contentType.split(";");
|
||||||
|
return new MediaType(values[0], StringUtils.isEmpty(charset) ? Constants.ENCODE : charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCharset() {
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return type + ";charset=" + charset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.common.http.param;
|
package com.alibaba.nacos.common.http.param;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.common.utils.MapUtils;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -68,9 +70,11 @@ public class Query {
|
|||||||
* @return this query
|
* @return this query
|
||||||
*/
|
*/
|
||||||
public Query initParams(Map<String, String> params) {
|
public Query initParams(Map<String, String> params) {
|
||||||
|
if (MapUtils.isNotEmpty(params)) {
|
||||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||||
addParam(entry.getKey(), entry.getValue());
|
addParam(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import java.util.Map;
|
|||||||
* Represents an HTTP request , consisting of headers and body.
|
* Represents an HTTP request , consisting of headers and body.
|
||||||
*
|
*
|
||||||
* @author mai.jh
|
* @author mai.jh
|
||||||
* @date 2020/5/23
|
|
||||||
*/
|
*/
|
||||||
public class RequestHttpEntity {
|
public class RequestHttpEntity {
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ public class RequestHttpEntity {
|
|||||||
|
|
||||||
private final Query query;
|
private final Query query;
|
||||||
|
|
||||||
private Object body;
|
private final Object body;
|
||||||
|
|
||||||
public RequestHttpEntity(Header header, Query query) {
|
public RequestHttpEntity(Header header, Query query) {
|
||||||
this(null, header, query);
|
this(null, header, query);
|
||||||
|
@ -96,6 +96,10 @@ public class DefaultSharePublisher extends DefaultPublisher {
|
|||||||
|
|
||||||
// Get for Map, the algorithm is O(1).
|
// Get for Map, the algorithm is O(1).
|
||||||
Set<Subscriber> subscribers = subMappings.get(slowEventType);
|
Set<Subscriber> subscribers = subMappings.get(slowEventType);
|
||||||
|
if (null == subscribers) {
|
||||||
|
LOGGER.debug("[NotifyCenter] No subscribers for slow event {}", slowEventType.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Notification single event subscriber
|
// Notification single event subscriber
|
||||||
for (Subscriber subscriber : subscribers) {
|
for (Subscriber subscriber : subscribers) {
|
||||||
|
@ -51,7 +51,11 @@ public final class ConvertUtils {
|
|||||||
if (StringUtils.isBlank(val)) {
|
if (StringUtils.isBlank(val)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return Integer.parseInt(val);
|
return Integer.parseInt(val);
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +81,11 @@ public final class ConvertUtils {
|
|||||||
if (StringUtils.isBlank(val)) {
|
if (StringUtils.isBlank(val)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return Long.parseLong(val);
|
return Long.parseLong(val);
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +100,11 @@ public final class ConvertUtils {
|
|||||||
if (StringUtils.isBlank(val)) {
|
if (StringUtils.isBlank(val)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return Boolean.parseBoolean(val);
|
return Boolean.parseBoolean(val);
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following utility functions are extracted from <link>org.apache.commons.lang3</link>
|
// The following utility functions are extracted from <link>org.apache.commons.lang3</link>
|
||||||
@ -126,7 +138,7 @@ public final class ConvertUtils {
|
|||||||
* @return the boolean value of the string, {@code false} if no match or the String is null
|
* @return the boolean value of the string, {@code false} if no match or the String is null
|
||||||
*/
|
*/
|
||||||
public static boolean toBoolean(final String str) {
|
public static boolean toBoolean(final String str) {
|
||||||
return toBooleanObject(str) == Boolean.TRUE;
|
return Boolean.TRUE.equals(toBooleanObject(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,8 +26,10 @@ public class HttpMethod {
|
|||||||
|
|
||||||
public static final String GET = "GET";
|
public static final String GET = "GET";
|
||||||
|
|
||||||
// this is only use in nacos, Custom request type, essentially a get request
|
/**
|
||||||
|
* this is only use in nacos, Custom request type, essentially a GET request, Mainly used for GET request parameters
|
||||||
|
* are relatively large,can not be placed on the URL, so it needs to be placed in the body.
|
||||||
|
*/
|
||||||
public static final String GET_LARGE = "GET-LARGE";
|
public static final String GET_LARGE = "GET-LARGE";
|
||||||
|
|
||||||
public static final String HEAD = "HEAD";
|
public static final String HEAD = "HEAD";
|
||||||
@ -40,6 +42,12 @@ public class HttpMethod {
|
|||||||
|
|
||||||
public static final String DELETE = "DELETE";
|
public static final String DELETE = "DELETE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is only use in nacos, Custom request type, essentially a DELETE request, Mainly used for DELETE request
|
||||||
|
* parameters are relatively large, can not be placed on the URL, so it needs to be placed in the body.
|
||||||
|
*/
|
||||||
|
public static final String DELETE_LARGE = "DELETE_LARGE";
|
||||||
|
|
||||||
public static final String OPTIONS = "OPTIONS";
|
public static final String OPTIONS = "OPTIONS";
|
||||||
|
|
||||||
public static final String TRACE = "TRACE";
|
public static final String TRACE = "TRACE";
|
||||||
|
@ -50,9 +50,9 @@ public class IoUtils {
|
|||||||
*
|
*
|
||||||
* @param raw compress stream
|
* @param raw compress stream
|
||||||
* @return byte array after decompress
|
* @return byte array after decompress
|
||||||
* @throws Exception exception
|
* @throws IOException exception
|
||||||
*/
|
*/
|
||||||
public static byte[] tryDecompress(InputStream raw) throws Exception {
|
public static byte[] tryDecompress(InputStream raw) throws IOException {
|
||||||
GZIPInputStream gis = null;
|
GZIPInputStream gis = null;
|
||||||
ByteArrayOutputStream out = null;
|
ByteArrayOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
@ -60,7 +60,7 @@ public class IoUtils {
|
|||||||
out = new ByteArrayOutputStream();
|
out = new ByteArrayOutputStream();
|
||||||
copy(gis, out);
|
copy(gis, out);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
} catch (Exception e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (out != null) {
|
if (out != null) {
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.http.param;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MediaTypeTest.
|
||||||
|
*
|
||||||
|
* @author mai.jh
|
||||||
|
*/
|
||||||
|
public class MediaTypeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValueOf() {
|
||||||
|
MediaType mediaType = MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
String type = "application/x-www-form-urlencoded";
|
||||||
|
String charset = "UTF-8";
|
||||||
|
assertEquals(type, mediaType.getType());
|
||||||
|
assertEquals(charset, mediaType.getCharset());
|
||||||
|
assertEquals(MediaType.APPLICATION_FORM_URLENCODED, mediaType.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValueOf2() {
|
||||||
|
MediaType mediaType = MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED, "ISO-8859-1");
|
||||||
|
String type = "application/x-www-form-urlencoded";
|
||||||
|
String charset = "ISO-8859-1";
|
||||||
|
String excepted = "application/x-www-form-urlencoded;charset=ISO-8859-1";
|
||||||
|
assertEquals(type, mediaType.getType());
|
||||||
|
assertEquals(charset, mediaType.getCharset());
|
||||||
|
assertEquals(excepted, mediaType.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValueOf3() {
|
||||||
|
MediaType mediaType = MediaType.valueOf("application/x-www-form-urlencoded", "ISO-8859-1");
|
||||||
|
String type = "application/x-www-form-urlencoded";
|
||||||
|
String charset = "ISO-8859-1";
|
||||||
|
String excepted = "application/x-www-form-urlencoded;charset=ISO-8859-1";
|
||||||
|
assertEquals(type, mediaType.getType());
|
||||||
|
assertEquals(charset, mediaType.getCharset());
|
||||||
|
assertEquals(excepted, mediaType.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -132,6 +132,7 @@ public class NotifyCenterTest {
|
|||||||
return ExpireEvent.class;
|
return ExpireEvent.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean ignoreExpireEvent() {
|
public boolean ignoreExpireEvent() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.alibaba.nacos.config.server.configuration;
|
package com.alibaba.nacos.config.server.configuration;
|
||||||
|
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.springframework.context.annotation.Condition;
|
import org.springframework.context.annotation.Condition;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.alibaba.nacos.config.server.configuration;
|
package com.alibaba.nacos.config.server.configuration;
|
||||||
|
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.springframework.context.annotation.Condition;
|
import org.springframework.context.annotation.Condition;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
@ -45,7 +45,7 @@ import com.alibaba.nacos.config.server.utils.ParamUtils;
|
|||||||
import com.alibaba.nacos.config.server.utils.RequestUtil;
|
import com.alibaba.nacos.config.server.utils.RequestUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.ZipUtils;
|
import com.alibaba.nacos.config.server.utils.ZipUtils;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -31,7 +31,7 @@ import com.alibaba.nacos.config.server.service.repository.PersistService;
|
|||||||
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
|
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
|
||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.WebUtils;
|
import com.alibaba.nacos.core.utils.WebUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -20,7 +20,7 @@ import com.alibaba.nacos.config.server.constant.Constants;
|
|||||||
import com.alibaba.nacos.config.server.service.datasource.DataSourceService;
|
import com.alibaba.nacos.config.server.service.datasource.DataSourceService;
|
||||||
import com.alibaba.nacos.config.server.service.datasource.DynamicDataSource;
|
import com.alibaba.nacos.config.server.service.datasource.DynamicDataSource;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.config.server.model.app;
|
package com.alibaba.nacos.config.server.model.app;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ApplicationInfo.
|
* ApplicationInfo.
|
||||||
|
@ -19,7 +19,7 @@ package com.alibaba.nacos.config.server.service;
|
|||||||
import com.alibaba.nacos.common.notify.NotifyCenter;
|
import com.alibaba.nacos.common.notify.NotifyCenter;
|
||||||
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
|
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConfigChangePublisher.
|
* ConfigChangePublisher.
|
||||||
|
@ -25,7 +25,7 @@ import com.alibaba.nacos.config.server.utils.ConfigExecutor;
|
|||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.core.cluster.Member;
|
import com.alibaba.nacos.core.cluster.Member;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -42,7 +42,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
|
|||||||
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
||||||
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
|
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,8 +21,8 @@ import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
|||||||
import com.alibaba.nacos.config.server.constant.Constants;
|
import com.alibaba.nacos.config.server.constant.Constants;
|
||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.DiskUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -49,8 +49,8 @@ import com.alibaba.nacos.config.server.utils.GroupKey2;
|
|||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import com.alibaba.nacos.core.utils.TimerContext;
|
import com.alibaba.nacos.core.utils.TimerContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -28,7 +28,7 @@ import com.alibaba.nacos.consistency.cp.CPProtocol;
|
|||||||
import com.alibaba.nacos.consistency.cp.MetadataKey;
|
import com.alibaba.nacos.consistency.cp.MetadataKey;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.distributed.ProtocolManager;
|
import com.alibaba.nacos.core.distributed.ProtocolManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.GlobalExecutor;
|
import com.alibaba.nacos.core.utils.GlobalExecutor;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -27,8 +27,8 @@ import com.alibaba.nacos.config.server.utils.ContentUtils;
|
|||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||||
import com.alibaba.nacos.core.distributed.ProtocolManager;
|
import com.alibaba.nacos.core.distributed.ProtocolManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -28,7 +28,7 @@ import com.alibaba.nacos.config.server.service.repository.PersistService;
|
|||||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||||
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -32,8 +32,8 @@ import com.alibaba.nacos.config.server.utils.ConfigExecutor;
|
|||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.core.cluster.Member;
|
import com.alibaba.nacos.core.cluster.Member;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -24,8 +24,8 @@ import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
|||||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||||
import com.alibaba.nacos.core.cluster.Member;
|
import com.alibaba.nacos.core.cluster.Member;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ import com.alibaba.nacos.consistency.snapshot.Reader;
|
|||||||
import com.alibaba.nacos.consistency.snapshot.SnapshotOperation;
|
import com.alibaba.nacos.consistency.snapshot.SnapshotOperation;
|
||||||
import com.alibaba.nacos.consistency.snapshot.Writer;
|
import com.alibaba.nacos.consistency.snapshot.Writer;
|
||||||
import com.alibaba.nacos.core.distributed.raft.utils.RaftExecutor;
|
import com.alibaba.nacos.core.distributed.raft.utils.RaftExecutor;
|
||||||
import com.alibaba.nacos.core.utils.DiskUtils;
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.TimerContext;
|
import com.alibaba.nacos.core.utils.TimerContext;
|
||||||
import com.alipay.sofa.jraft.util.CRC64;
|
import com.alipay.sofa.jraft.util.CRC64;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ import com.alibaba.nacos.consistency.snapshot.SnapshotOperation;
|
|||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.distributed.ProtocolManager;
|
import com.alibaba.nacos.core.distributed.ProtocolManager;
|
||||||
import com.alibaba.nacos.core.utils.ClassUtils;
|
import com.alibaba.nacos.core.utils.ClassUtils;
|
||||||
import com.alibaba.nacos.core.utils.DiskUtils;
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import com.alibaba.nacos.core.utils.GenericType;
|
import com.alibaba.nacos.core.utils.GenericType;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
@ -24,7 +24,7 @@ import com.alibaba.nacos.config.server.service.datasource.DataSourceService;
|
|||||||
import com.alibaba.nacos.config.server.service.datasource.DynamicDataSource;
|
import com.alibaba.nacos.config.server.service.datasource.DynamicDataSource;
|
||||||
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
|
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
|
||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.core.utils.DiskUtils;
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
@ -20,7 +20,7 @@ import com.alibaba.nacos.config.server.model.Page;
|
|||||||
import com.alibaba.nacos.config.server.service.repository.PaginationHelper;
|
import com.alibaba.nacos.config.server.service.repository.PaginationHelper;
|
||||||
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
|
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
|
|||||||
import com.alibaba.nacos.config.server.constant.Constants;
|
import com.alibaba.nacos.config.server.constant.Constants;
|
||||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||||
import com.alibaba.nacos.config.server.model.event.ConfigDumpEvent;
|
import com.alibaba.nacos.config.server.model.event.ConfigDumpEvent;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -20,7 +20,7 @@ import com.alibaba.nacos.common.utils.MD5Utils;
|
|||||||
import com.alibaba.nacos.config.server.constant.Constants;
|
import com.alibaba.nacos.config.server.constant.Constants;
|
||||||
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
||||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ package com.alibaba.nacos.config.server.utils;
|
|||||||
import com.alibaba.nacos.common.utils.IoUtils;
|
import com.alibaba.nacos.common.utils.IoUtils;
|
||||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||||
import com.alibaba.nacos.config.server.constant.Constants;
|
import com.alibaba.nacos.config.server.constant.Constants;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.config.server.utils;
|
package com.alibaba.nacos.config.server.utils;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
import org.springframework.context.ApplicationContextInitializer;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
@ -19,7 +19,7 @@ package com.alibaba.nacos.config.server.model;
|
|||||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||||
import com.alibaba.nacos.consistency.IdGenerator;
|
import com.alibaba.nacos.consistency.IdGenerator;
|
||||||
import com.alibaba.nacos.core.distributed.id.SnowFlowerIdGenerator;
|
import com.alibaba.nacos.core.distributed.id.SnowFlowerIdGenerator;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
|
@ -21,7 +21,7 @@ import com.alibaba.nacos.common.notify.NotifyCenter;
|
|||||||
import com.alibaba.nacos.common.notify.listener.Subscriber;
|
import com.alibaba.nacos.common.notify.listener.Subscriber;
|
||||||
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
|
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
|
||||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.alibaba.nacos.console.controller;
|
package com.alibaba.nacos.console.controller;
|
||||||
|
|
||||||
import com.alibaba.nacos.common.utils.VersionUtils;
|
import com.alibaba.nacos.common.utils.VersionUtils;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -175,3 +175,4 @@ nacos.istio.mcp.server.enabled=false
|
|||||||
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
|
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
|
||||||
### rpc request timeout, default 5 seconds
|
### rpc request timeout, default 5 seconds
|
||||||
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000
|
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import com.alibaba.nacos.auth.model.Permission;
|
|||||||
import com.alibaba.nacos.auth.parser.ResourceParser;
|
import com.alibaba.nacos.auth.parser.ResourceParser;
|
||||||
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
||||||
import com.alibaba.nacos.core.code.ControllerMethodsCache;
|
import com.alibaba.nacos.core.code.ControllerMethodsCache;
|
||||||
import com.alibaba.nacos.core.utils.Constants;
|
import com.alibaba.nacos.sys.env.Constants;
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
import com.alibaba.nacos.core.utils.WebUtils;
|
import com.alibaba.nacos.core.utils.WebUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.core.auth.condition;
|
package com.alibaba.nacos.core.auth.condition;
|
||||||
|
|
||||||
import static com.alibaba.nacos.core.utils.Constants.REQUEST_PATH_SEPARATOR;
|
import static com.alibaba.nacos.sys.env.Constants.REQUEST_PATH_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* request path info. method:{@link org.springframework.web.bind.annotation.RequestMapping#method()} path: {@link
|
* request path info. method:{@link org.springframework.web.bind.annotation.RequestMapping#method()} path: {@link
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.core.cluster;
|
package com.alibaba.nacos.core.cluster;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -17,9 +17,8 @@
|
|||||||
package com.alibaba.nacos.core.cluster;
|
package com.alibaba.nacos.core.cluster;
|
||||||
|
|
||||||
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
||||||
import com.alibaba.nacos.common.utils.VersionUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -32,13 +32,13 @@ import com.alibaba.nacos.common.utils.ConcurrentHashSet;
|
|||||||
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
||||||
import com.alibaba.nacos.common.utils.VersionUtils;
|
import com.alibaba.nacos.common.utils.VersionUtils;
|
||||||
import com.alibaba.nacos.core.cluster.lookup.LookupFactory;
|
import com.alibaba.nacos.core.cluster.lookup.LookupFactory;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.Commons;
|
import com.alibaba.nacos.core.utils.Commons;
|
||||||
import com.alibaba.nacos.core.utils.Constants;
|
|
||||||
import com.alibaba.nacos.core.utils.GenericType;
|
import com.alibaba.nacos.core.utils.GenericType;
|
||||||
import com.alibaba.nacos.core.utils.GlobalExecutor;
|
import com.alibaba.nacos.core.utils.GlobalExecutor;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
|
import com.alibaba.nacos.sys.env.Constants;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
|
@ -25,10 +25,10 @@ import com.alibaba.nacos.common.model.RestResult;
|
|||||||
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
import com.alibaba.nacos.common.utils.ExceptionUtil;
|
||||||
import com.alibaba.nacos.core.cluster.AbstractMemberLookup;
|
import com.alibaba.nacos.core.cluster.AbstractMemberLookup;
|
||||||
import com.alibaba.nacos.core.cluster.MemberUtils;
|
import com.alibaba.nacos.core.cluster.MemberUtils;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.GenericType;
|
import com.alibaba.nacos.core.utils.GenericType;
|
||||||
import com.alibaba.nacos.core.utils.GlobalExecutor;
|
import com.alibaba.nacos.core.utils.GlobalExecutor;
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
@ -20,11 +20,11 @@ import com.alibaba.nacos.api.exception.NacosException;
|
|||||||
import com.alibaba.nacos.core.cluster.AbstractMemberLookup;
|
import com.alibaba.nacos.core.cluster.AbstractMemberLookup;
|
||||||
import com.alibaba.nacos.core.cluster.Member;
|
import com.alibaba.nacos.core.cluster.Member;
|
||||||
import com.alibaba.nacos.core.cluster.MemberUtils;
|
import com.alibaba.nacos.core.cluster.MemberUtils;
|
||||||
import com.alibaba.nacos.core.file.FileChangeEvent;
|
import com.alibaba.nacos.sys.file.FileChangeEvent;
|
||||||
import com.alibaba.nacos.core.file.FileWatcher;
|
import com.alibaba.nacos.sys.file.FileWatcher;
|
||||||
import com.alibaba.nacos.core.file.WatchFileCenter;
|
import com.alibaba.nacos.sys.file.WatchFileCenter;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -20,7 +20,7 @@ import com.alibaba.nacos.api.exception.NacosException;
|
|||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
import com.alibaba.nacos.core.cluster.MemberLookup;
|
import com.alibaba.nacos.core.cluster.MemberLookup;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
package com.alibaba.nacos.core.cluster.lookup;
|
package com.alibaba.nacos.core.cluster.lookup;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.cluster.AbstractMemberLookup;
|
import com.alibaba.nacos.core.cluster.AbstractMemberLookup;
|
||||||
|
import com.alibaba.nacos.core.cluster.MemberUtils;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
@ -30,7 +33,8 @@ public class StandaloneMemberLookup extends AbstractMemberLookup {
|
|||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
if (start.compareAndSet(false, true)) {
|
if (start.compareAndSet(false, true)) {
|
||||||
afterLookup(Collections.singletonList(memberManager.getSelf()));
|
String url = InetUtils.getSelfIp() + ":" + ApplicationUtils.getPort();
|
||||||
|
afterLookup(MemberUtils.readServerConf(Collections.singletonList(url)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,8 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import static com.alibaba.nacos.core.utils.Constants.REQUEST_PATH_SEPARATOR;
|
import static com.alibaba.nacos.sys.env.Constants.REQUEST_PATH_SEPARATOR;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method cache.
|
* Method cache.
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.core.code;
|
package com.alibaba.nacos.core.code;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.core.code;
|
package com.alibaba.nacos.core.code;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||||
@ -27,8 +27,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static com.alibaba.nacos.core.utils.Constants.STANDALONE_MODE_PROPERTY_NAME;
|
import static com.alibaba.nacos.sys.env.Constants.STANDALONE_MODE_PROPERTY_NAME;
|
||||||
import static com.alibaba.nacos.core.utils.Constants.STANDALONE_SPRING_PROFILE;
|
import static com.alibaba.nacos.sys.env.Constants.STANDALONE_SPRING_PROFILE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standalone {@link Profile} {@link ApplicationListener} for {@link ApplicationEnvironmentPreparedEvent}.
|
* Standalone {@link Profile} {@link ApplicationListener} for {@link ApplicationEnvironmentPreparedEvent}.
|
||||||
|
@ -21,10 +21,10 @@ import com.alibaba.nacos.common.executor.NameThreadFactory;
|
|||||||
import com.alibaba.nacos.common.executor.ThreadPoolManager;
|
import com.alibaba.nacos.common.executor.ThreadPoolManager;
|
||||||
import com.alibaba.nacos.common.http.HttpClientManager;
|
import com.alibaba.nacos.common.http.HttpClientManager;
|
||||||
import com.alibaba.nacos.common.notify.NotifyCenter;
|
import com.alibaba.nacos.common.notify.NotifyCenter;
|
||||||
import com.alibaba.nacos.core.file.WatchFileCenter;
|
import com.alibaba.nacos.sys.file.WatchFileCenter;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.DiskUtils;
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import com.alibaba.nacos.core.utils.InetUtils;
|
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -29,7 +29,7 @@ import com.alibaba.nacos.core.cluster.Member;
|
|||||||
import com.alibaba.nacos.core.cluster.MemberUtils;
|
import com.alibaba.nacos.core.cluster.MemberUtils;
|
||||||
import com.alibaba.nacos.core.cluster.NodeState;
|
import com.alibaba.nacos.core.cluster.NodeState;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.Commons;
|
import com.alibaba.nacos.core.utils.Commons;
|
||||||
import com.alibaba.nacos.core.utils.GenericType;
|
import com.alibaba.nacos.core.utils.GenericType;
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
|
@ -26,7 +26,7 @@ import com.alibaba.nacos.core.cluster.MemberChangeListener;
|
|||||||
import com.alibaba.nacos.core.cluster.MemberMetaDataConstants;
|
import com.alibaba.nacos.core.cluster.MemberMetaDataConstants;
|
||||||
import com.alibaba.nacos.core.cluster.MemberUtils;
|
import com.alibaba.nacos.core.cluster.MemberUtils;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.ClassUtils;
|
import com.alibaba.nacos.core.utils.ClassUtils;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -109,7 +109,7 @@ public class DistroLoadDataTask implements Runnable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Loggers.DISTRO.error("[DISTRO-INIT] load snapshot {} from {} failed.", resourceType, each.getAddress());
|
Loggers.DISTRO.error("[DISTRO-INIT] load snapshot {} from {} failed.", resourceType, each.getAddress(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.alibaba.nacos.core.distributed.id;
|
package com.alibaba.nacos.core.distributed.id;
|
||||||
|
|
||||||
import com.alibaba.nacos.consistency.IdGenerator;
|
import com.alibaba.nacos.consistency.IdGenerator;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -39,7 +39,7 @@ import com.alibaba.nacos.core.distributed.raft.utils.JRaftUtils;
|
|||||||
import com.alibaba.nacos.core.distributed.raft.utils.RaftExecutor;
|
import com.alibaba.nacos.core.distributed.raft.utils.RaftExecutor;
|
||||||
import com.alibaba.nacos.core.distributed.raft.utils.RaftOptionsBuilder;
|
import com.alibaba.nacos.core.distributed.raft.utils.RaftOptionsBuilder;
|
||||||
import com.alibaba.nacos.core.monitor.MetricsMonitor;
|
import com.alibaba.nacos.core.monitor.MetricsMonitor;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
import com.alipay.sofa.jraft.CliService;
|
import com.alipay.sofa.jraft.CliService;
|
||||||
import com.alipay.sofa.jraft.Node;
|
import com.alipay.sofa.jraft.Node;
|
||||||
|
@ -25,9 +25,9 @@ import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
|||||||
import com.alibaba.nacos.core.distributed.raft.JRaftServer;
|
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.NacosGetRequestProcessor;
|
||||||
import com.alibaba.nacos.core.distributed.raft.processor.NacosLogProcessor;
|
import com.alibaba.nacos.core.distributed.raft.processor.NacosLogProcessor;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.core.utils.DiskUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
import com.alibaba.nacos.core.utils.Loggers;
|
||||||
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import com.alipay.sofa.jraft.CliService;
|
import com.alipay.sofa.jraft.CliService;
|
||||||
import com.alipay.sofa.jraft.RouteTable;
|
import com.alipay.sofa.jraft.RouteTable;
|
||||||
import com.alipay.sofa.jraft.Status;
|
import com.alipay.sofa.jraft.Status;
|
||||||
|
@ -1,81 +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.utils;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* operation property.
|
|
||||||
*
|
|
||||||
* @author Nacos
|
|
||||||
*/
|
|
||||||
public class PropertyUtil {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(PropertyUtil.class);
|
|
||||||
|
|
||||||
private static Properties properties = new Properties();
|
|
||||||
|
|
||||||
static {
|
|
||||||
InputStream inputStream = null;
|
|
||||||
try {
|
|
||||||
String baseDir = System.getProperty("nacos.home");
|
|
||||||
if (StringUtils.isNotBlank(baseDir)) {
|
|
||||||
inputStream = new FileInputStream(baseDir + "/conf/application.properties");
|
|
||||||
} else {
|
|
||||||
inputStream = PropertyUtil.class.getResourceAsStream("/application.properties");
|
|
||||||
}
|
|
||||||
properties.load(inputStream);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("read property file error:" + e);
|
|
||||||
} finally {
|
|
||||||
IOUtils.closeQuietly(inputStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getProperty(String key) {
|
|
||||||
return properties.getProperty(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getProperty(String key, String defaultValue) {
|
|
||||||
return properties.getProperty(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getPropertyList(String key) {
|
|
||||||
List<String> valueList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
|
||||||
String value = properties.getProperty(key + "[" + i + "]");
|
|
||||||
if (StringUtils.isBlank(value)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
valueList.add(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return valueList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -16,11 +16,13 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.core.utils;
|
package com.alibaba.nacos.core.utils;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.common.utils.LoggerUtils;
|
import com.alibaba.nacos.common.utils.LoggerUtils;
|
||||||
import com.alibaba.nacos.common.utils.Pair;
|
import com.alibaba.nacos.common.utils.Pair;
|
||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
@ -20,6 +20,7 @@ import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
|||||||
import com.alibaba.nacos.common.http.HttpUtils;
|
import com.alibaba.nacos.common.http.HttpUtils;
|
||||||
import com.alibaba.nacos.common.model.RestResult;
|
import com.alibaba.nacos.common.model.RestResult;
|
||||||
import com.alibaba.nacos.common.model.RestResultUtils;
|
import com.alibaba.nacos.common.model.RestResultUtils;
|
||||||
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.web.context.request.async.DeferredResult;
|
import org.springframework.web.context.request.async.DeferredResult;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -205,7 +205,7 @@
|
|||||||
<level value="INFO"/>
|
<level value="INFO"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<logger name="com.alibaba.nacos.core.file.WatchFileCenter">
|
<logger name="com.alibaba.nacos.sys.file.WatchFileCenter">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
<level value="INFO"/>
|
<level value="INFO"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
# ApplicationContextInitializer
|
|
||||||
org.springframework.context.ApplicationContextInitializer=\
|
|
||||||
com.alibaba.nacos.core.utils.ApplicationUtils
|
|
||||||
|
|
||||||
# ApplicationListener
|
# ApplicationListener
|
||||||
org.springframework.context.ApplicationListener=\
|
org.springframework.context.ApplicationListener=\
|
||||||
com.alibaba.nacos.core.code.StandaloneProfileApplicationListener
|
com.alibaba.nacos.core.code.StandaloneProfileApplicationListener
|
||||||
|
|
||||||
# EnvironmentPostProcessor
|
|
||||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
|
||||||
com.alibaba.nacos.core.env.NacosDefaultPropertySourceEnvironmentPostProcessor
|
|
||||||
|
|
||||||
# SpringApplicationRunListener
|
# SpringApplicationRunListener
|
||||||
org.springframework.boot.SpringApplicationRunListener=\
|
org.springframework.boot.SpringApplicationRunListener=\
|
||||||
com.alibaba.nacos.core.code.LoggingSpringApplicationRunListener,\
|
com.alibaba.nacos.core.code.LoggingSpringApplicationRunListener,\
|
||||||
|
@ -27,7 +27,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import static com.alibaba.nacos.core.utils.Constants.STANDALONE_SPRING_PROFILE;
|
import static com.alibaba.nacos.sys.env.Constants.STANDALONE_SPRING_PROFILE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link StandaloneProfileApplicationListener} Test.
|
* {@link StandaloneProfileApplicationListener} Test.
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.core.utils;
|
package com.alibaba.nacos.core.utils;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@ -26,8 +27,8 @@ import java.io.IOException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static com.alibaba.nacos.core.utils.Constants.PREFER_HOSTNAME_OVER_IP_PROPERTY_NAME;
|
import static com.alibaba.nacos.sys.env.Constants.PREFER_HOSTNAME_OVER_IP_PROPERTY_NAME;
|
||||||
import static com.alibaba.nacos.core.utils.Constants.STANDALONE_MODE_PROPERTY_NAME;
|
import static com.alibaba.nacos.sys.env.Constants.STANDALONE_MODE_PROPERTY_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ApplicationUtils} Test.
|
* {@link ApplicationUtils} Test.
|
||||||
|
@ -624,7 +624,7 @@
|
|||||||
<level value="INFO"/>
|
<level value="INFO"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<logger name="com.alibaba.nacos.core.file.WatchFileCenter">
|
<logger name="com.alibaba.nacos.sys.file.WatchFileCenter">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
<level value="INFO"/>
|
<level value="INFO"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
@ -24,7 +24,7 @@ import com.alibaba.nacos.core.cluster.MemberChangeListener;
|
|||||||
import com.alibaba.nacos.core.cluster.MemberMetaDataConstants;
|
import com.alibaba.nacos.core.cluster.MemberMetaDataConstants;
|
||||||
import com.alibaba.nacos.core.cluster.NodeState;
|
import com.alibaba.nacos.core.cluster.NodeState;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
|
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
|
||||||
import com.alibaba.nacos.naming.misc.GlobalExecutor;
|
import com.alibaba.nacos.naming.misc.GlobalExecutor;
|
||||||
import com.alibaba.nacos.naming.misc.Loggers;
|
import com.alibaba.nacos.naming.misc.Loggers;
|
||||||
|
@ -19,7 +19,6 @@ package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
|||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.common.utils.Objects;
|
import com.alibaba.nacos.common.utils.Objects;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
|
||||||
import com.alibaba.nacos.naming.cluster.ServerStatus;
|
import com.alibaba.nacos.naming.cluster.ServerStatus;
|
||||||
import com.alibaba.nacos.naming.cluster.transport.Serializer;
|
import com.alibaba.nacos.naming.cluster.transport.Serializer;
|
||||||
import com.alibaba.nacos.consistency.DataOperation;
|
import com.alibaba.nacos.consistency.DataOperation;
|
||||||
@ -28,16 +27,10 @@ import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
|||||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||||
import com.alibaba.nacos.naming.consistency.ephemeral.EphemeralConsistencyService;
|
import com.alibaba.nacos.naming.consistency.ephemeral.EphemeralConsistencyService;
|
||||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpCombinedKey;
|
import com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpCombinedKey;
|
||||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpCombinedKeyTaskFailedHandler;
|
|
||||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpDelayTaskProcessor;
|
|
||||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.component.DistroDataStorageImpl;
|
|
||||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.component.DistroHttpAgent;
|
|
||||||
import com.alibaba.nacos.core.distributed.distro.DistroProtocol;
|
import com.alibaba.nacos.core.distributed.distro.DistroProtocol;
|
||||||
import com.alibaba.nacos.core.distributed.distro.component.DistroComponentHolder;
|
|
||||||
import com.alibaba.nacos.core.distributed.distro.component.DistroDataProcessor;
|
import com.alibaba.nacos.core.distributed.distro.component.DistroDataProcessor;
|
||||||
import com.alibaba.nacos.core.distributed.distro.entity.DistroData;
|
import com.alibaba.nacos.core.distributed.distro.entity.DistroData;
|
||||||
import com.alibaba.nacos.core.distributed.distro.entity.DistroKey;
|
import com.alibaba.nacos.core.distributed.distro.entity.DistroKey;
|
||||||
import com.alibaba.nacos.core.distributed.distro.task.DistroTaskEngineHolder;
|
|
||||||
import com.alibaba.nacos.naming.core.DistroMapper;
|
import com.alibaba.nacos.naming.core.DistroMapper;
|
||||||
import com.alibaba.nacos.naming.core.Instances;
|
import com.alibaba.nacos.naming.core.Instances;
|
||||||
import com.alibaba.nacos.naming.core.Service;
|
import com.alibaba.nacos.naming.core.Service;
|
||||||
@ -102,20 +95,6 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService
|
|||||||
this.switchDomain = switchDomain;
|
this.switchDomain = switchDomain;
|
||||||
this.globalConfig = globalConfig;
|
this.globalConfig = globalConfig;
|
||||||
this.distroProtocol = distroProtocol;
|
this.distroProtocol = distroProtocol;
|
||||||
registerDistroComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerDistroComponent() {
|
|
||||||
DistroComponentHolder componentHolder = ApplicationUtils.getBean(DistroComponentHolder.class);
|
|
||||||
DistroTaskEngineHolder taskEngineHolder = ApplicationUtils.getBean(DistroTaskEngineHolder.class);
|
|
||||||
componentHolder.registerDataStorage(KeyBuilder.INSTANCE_LIST_KEY_PREFIX,
|
|
||||||
new DistroDataStorageImpl(dataStore, distroMapper));
|
|
||||||
componentHolder.registerTransportAgent(KeyBuilder.INSTANCE_LIST_KEY_PREFIX, new DistroHttpAgent());
|
|
||||||
componentHolder.registerFailedTaskHandler(KeyBuilder.INSTANCE_LIST_KEY_PREFIX,
|
|
||||||
new DistroHttpCombinedKeyTaskFailedHandler(globalConfig, taskEngineHolder));
|
|
||||||
taskEngineHolder.registerNacosTaskProcessor(KeyBuilder.INSTANCE_LIST_KEY_PREFIX,
|
|
||||||
new DistroHttpDelayTaskProcessor(globalConfig, taskEngineHolder));
|
|
||||||
componentHolder.registerDataProcessor(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
|
@ -33,8 +33,8 @@ public class DistroHttpData extends DistroData {
|
|||||||
|
|
||||||
private Object deserializedContent;
|
private Object deserializedContent;
|
||||||
|
|
||||||
public DistroHttpData(DistroKey distroKey, byte[] content, Object deserializedContent) {
|
public DistroHttpData(DistroKey distroKey, Object deserializedContent) {
|
||||||
super(distroKey, content);
|
setDistroKey(distroKey);
|
||||||
this.deserializedContent = deserializedContent;
|
this.deserializedContent = deserializedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.consistency.ephemeral.distro;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.core.distributed.distro.component.DistroComponentHolder;
|
||||||
|
import com.alibaba.nacos.core.distributed.distro.task.DistroTaskEngineHolder;
|
||||||
|
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||||
|
import com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpCombinedKeyTaskFailedHandler;
|
||||||
|
import com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpDelayTaskProcessor;
|
||||||
|
import com.alibaba.nacos.naming.consistency.ephemeral.distro.component.DistroDataStorageImpl;
|
||||||
|
import com.alibaba.nacos.naming.consistency.ephemeral.distro.component.DistroHttpAgent;
|
||||||
|
import com.alibaba.nacos.naming.core.DistroMapper;
|
||||||
|
import com.alibaba.nacos.naming.misc.GlobalConfig;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distro http registry.
|
||||||
|
*
|
||||||
|
* @author xiweng.yy
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class DistroHttpRegistry {
|
||||||
|
|
||||||
|
private final DistroComponentHolder componentHolder;
|
||||||
|
|
||||||
|
private final DistroTaskEngineHolder taskEngineHolder;
|
||||||
|
|
||||||
|
private final DataStore dataStore;
|
||||||
|
|
||||||
|
private final DistroMapper distroMapper;
|
||||||
|
|
||||||
|
private final GlobalConfig globalConfig;
|
||||||
|
|
||||||
|
private final DistroConsistencyServiceImpl consistencyService;
|
||||||
|
|
||||||
|
public DistroHttpRegistry(DistroComponentHolder componentHolder, DistroTaskEngineHolder taskEngineHolder,
|
||||||
|
DataStore dataStore, DistroMapper distroMapper, GlobalConfig globalConfig,
|
||||||
|
DistroConsistencyServiceImpl consistencyService) {
|
||||||
|
this.componentHolder = componentHolder;
|
||||||
|
this.taskEngineHolder = taskEngineHolder;
|
||||||
|
this.dataStore = dataStore;
|
||||||
|
this.distroMapper = distroMapper;
|
||||||
|
this.globalConfig = globalConfig;
|
||||||
|
this.consistencyService = consistencyService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register necessary component to distro protocol for HTTP implement.
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void doRegister() {
|
||||||
|
componentHolder.registerDataStorage(KeyBuilder.INSTANCE_LIST_KEY_PREFIX,
|
||||||
|
new DistroDataStorageImpl(dataStore, distroMapper));
|
||||||
|
componentHolder.registerTransportAgent(KeyBuilder.INSTANCE_LIST_KEY_PREFIX, new DistroHttpAgent());
|
||||||
|
componentHolder.registerFailedTaskHandler(KeyBuilder.INSTANCE_LIST_KEY_PREFIX,
|
||||||
|
new DistroHttpCombinedKeyTaskFailedHandler(globalConfig, taskEngineHolder));
|
||||||
|
taskEngineHolder.registerNacosTaskProcessor(KeyBuilder.INSTANCE_LIST_KEY_PREFIX,
|
||||||
|
new DistroHttpDelayTaskProcessor(globalConfig, taskEngineHolder));
|
||||||
|
componentHolder.registerDataProcessor(consistencyService);
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro.component;
|
package com.alibaba.nacos.naming.consistency.ephemeral.distro.component;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.naming.cluster.transport.Serializer;
|
import com.alibaba.nacos.naming.cluster.transport.Serializer;
|
||||||
import com.alibaba.nacos.naming.consistency.Datum;
|
import com.alibaba.nacos.naming.consistency.Datum;
|
||||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||||
|
@ -22,6 +22,7 @@ import com.alibaba.nacos.core.exception.KvStorageException;
|
|||||||
import com.alibaba.nacos.core.storage.StorageFactory;
|
import com.alibaba.nacos.core.storage.StorageFactory;
|
||||||
import com.alibaba.nacos.core.storage.kv.KvStorage;
|
import com.alibaba.nacos.core.storage.kv.KvStorage;
|
||||||
import com.alibaba.nacos.core.storage.kv.MemoryKvStorage;
|
import com.alibaba.nacos.core.storage.kv.MemoryKvStorage;
|
||||||
|
import com.alibaba.nacos.core.utils.TimerContext;
|
||||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||||
import com.alibaba.nacos.naming.misc.Loggers;
|
import com.alibaba.nacos.naming.misc.Loggers;
|
||||||
|
|
||||||
@ -136,12 +137,19 @@ public class NamingKvStorage extends MemoryKvStorage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void snapshotLoad(String path) throws KvStorageException {
|
public void snapshotLoad(String path) throws KvStorageException {
|
||||||
final long startTime = System.currentTimeMillis();
|
final KvStorageException e = TimerContext.run(() -> {
|
||||||
|
try {
|
||||||
baseDirStorage.snapshotLoad(path);
|
baseDirStorage.snapshotLoad(path);
|
||||||
loadSnapshotFromActualStorage(baseDirStorage);
|
loadSnapshotFromActualStorage(baseDirStorage);
|
||||||
loadNamespaceSnapshot();
|
loadNamespaceSnapshot();
|
||||||
long costTime = System.currentTimeMillis() - startTime;
|
return null;
|
||||||
Loggers.RAFT.info("load snapshot cost time {}ms", costTime);
|
} catch (KvStorageException exception) {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
}, "naming kv storage load snapshot", Loggers.RAFT);
|
||||||
|
if (e != null) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSnapshotFromActualStorage(KvStorage actualStorage) throws KvStorageException {
|
private void loadSnapshotFromActualStorage(KvStorage actualStorage) throws KvStorageException {
|
||||||
|
@ -23,9 +23,9 @@ import com.alibaba.nacos.consistency.snapshot.SnapshotOperation;
|
|||||||
import com.alibaba.nacos.consistency.snapshot.Writer;
|
import com.alibaba.nacos.consistency.snapshot.Writer;
|
||||||
import com.alibaba.nacos.core.distributed.raft.utils.RaftExecutor;
|
import com.alibaba.nacos.core.distributed.raft.utils.RaftExecutor;
|
||||||
import com.alibaba.nacos.core.storage.kv.KvStorage;
|
import com.alibaba.nacos.core.storage.kv.KvStorage;
|
||||||
import com.alibaba.nacos.core.utils.DiskUtils;
|
|
||||||
import com.alibaba.nacos.core.utils.TimerContext;
|
import com.alibaba.nacos.core.utils.TimerContext;
|
||||||
import com.alibaba.nacos.naming.misc.Loggers;
|
import com.alibaba.nacos.naming.misc.Loggers;
|
||||||
|
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||||
import com.alipay.sofa.jraft.util.CRC64;
|
import com.alipay.sofa.jraft.util.CRC64;
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -35,7 +35,6 @@ import com.alibaba.nacos.core.distributed.ProtocolManager;
|
|||||||
import com.alibaba.nacos.core.exception.ErrorCode;
|
import com.alibaba.nacos.core.exception.ErrorCode;
|
||||||
import com.alibaba.nacos.core.exception.KvStorageException;
|
import com.alibaba.nacos.core.exception.KvStorageException;
|
||||||
import com.alibaba.nacos.core.storage.kv.KvStorage;
|
import com.alibaba.nacos.core.storage.kv.KvStorage;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
|
||||||
import com.alibaba.nacos.naming.consistency.Datum;
|
import com.alibaba.nacos.naming.consistency.Datum;
|
||||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||||
@ -47,6 +46,7 @@ import com.alibaba.nacos.naming.misc.Loggers;
|
|||||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||||
import com.alibaba.nacos.naming.pojo.Record;
|
import com.alibaba.nacos.naming.pojo.Record;
|
||||||
import com.alibaba.nacos.naming.utils.Constants;
|
import com.alibaba.nacos.naming.utils.Constants;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -16,21 +16,18 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.naming.consistency.persistent.raft;
|
package com.alibaba.nacos.naming.consistency.persistent.raft;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.common.executor.ExecutorFactory;
|
||||||
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
import com.alibaba.nacos.common.executor.NameThreadFactory;
|
||||||
import com.alibaba.nacos.common.lifecycle.Closeable;
|
import com.alibaba.nacos.common.http.Callback;
|
||||||
import com.alibaba.nacos.common.notify.EventPublisher;
|
import com.alibaba.nacos.common.model.RestResult;
|
||||||
import com.alibaba.nacos.common.notify.NotifyCenter;
|
|
||||||
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
|
|
||||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||||
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.consistency.DataOperation;
|
import com.alibaba.nacos.consistency.DataOperation;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.core.utils.ClassUtils;
|
||||||
|
import com.alibaba.nacos.naming.NamingApp;
|
||||||
import com.alibaba.nacos.naming.consistency.Datum;
|
import com.alibaba.nacos.naming.consistency.Datum;
|
||||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||||
import com.alibaba.nacos.naming.consistency.ValueChangeEvent;
|
|
||||||
import com.alibaba.nacos.naming.consistency.persistent.ClusterVersionJudgement;
|
|
||||||
import com.alibaba.nacos.naming.consistency.persistent.PersistentNotifier;
|
|
||||||
import com.alibaba.nacos.naming.core.Instances;
|
import com.alibaba.nacos.naming.core.Instances;
|
||||||
import com.alibaba.nacos.naming.core.Service;
|
import com.alibaba.nacos.naming.core.Service;
|
||||||
import com.alibaba.nacos.naming.misc.GlobalConfig;
|
import com.alibaba.nacos.naming.misc.GlobalConfig;
|
||||||
@ -46,10 +43,10 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.ning.http.client.AsyncCompletionHandler;
|
|
||||||
import com.ning.http.client.Response;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
|
import org.javatuples.Pair;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -58,7 +55,6 @@ import javax.annotation.PostConstruct;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -67,10 +63,13 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@ -80,12 +79,10 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
* Raft core code.
|
* Raft core code.
|
||||||
*
|
*
|
||||||
* @author nacos
|
* @author nacos
|
||||||
* @deprecated will remove in 1.4.x
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@DependsOn("ProtocolManager")
|
@DependsOn("ProtocolManager")
|
||||||
@Component
|
@Component
|
||||||
public class RaftCore implements Closeable {
|
public class RaftCore {
|
||||||
|
|
||||||
public static final String API_VOTE = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/vote";
|
public static final String API_VOTE = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/vote";
|
||||||
|
|
||||||
@ -103,6 +100,10 @@ public class RaftCore implements Closeable {
|
|||||||
|
|
||||||
public static final String API_GET_PEER = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/peer";
|
public static final String API_GET_PEER = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/peer";
|
||||||
|
|
||||||
|
private final ScheduledExecutorService executor = ExecutorFactory.Managed
|
||||||
|
.newSingleScheduledExecutorService(ClassUtils.getCanonicalName(NamingApp.class),
|
||||||
|
new NameThreadFactory("com.alibaba.nacos.naming.raft.notifier"));
|
||||||
|
|
||||||
public static final Lock OPERATE_LOCK = new ReentrantLock();
|
public static final Lock OPERATE_LOCK = new ReentrantLock();
|
||||||
|
|
||||||
public static final int PUBLISH_TERM_INCREASE_COUNT = 100;
|
public static final int PUBLISH_TERM_INCREASE_COUNT = 100;
|
||||||
@ -111,42 +112,25 @@ public class RaftCore implements Closeable {
|
|||||||
|
|
||||||
private volatile ConcurrentMap<String, Datum> datums = new ConcurrentHashMap<>();
|
private volatile ConcurrentMap<String, Datum> datums = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
private RaftPeerSet peers;
|
private RaftPeerSet peers;
|
||||||
|
|
||||||
private final SwitchDomain switchDomain;
|
@Autowired
|
||||||
|
private SwitchDomain switchDomain;
|
||||||
|
|
||||||
private final GlobalConfig globalConfig;
|
@Autowired
|
||||||
|
private GlobalConfig globalConfig;
|
||||||
|
|
||||||
private final RaftProxy raftProxy;
|
@Autowired
|
||||||
|
private RaftProxy raftProxy;
|
||||||
|
|
||||||
private final RaftStore raftStore;
|
@Autowired
|
||||||
|
private RaftStore raftStore;
|
||||||
|
|
||||||
private final ClusterVersionJudgement versionJudgement;
|
public volatile Notifier notifier = new Notifier();
|
||||||
|
|
||||||
public final PersistentNotifier notifier;
|
|
||||||
|
|
||||||
private final EventPublisher publisher;
|
|
||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
private volatile boolean stopWork = false;
|
|
||||||
|
|
||||||
private ScheduledFuture masterTask = null;
|
|
||||||
|
|
||||||
private ScheduledFuture heartbeatTask = null;
|
|
||||||
|
|
||||||
public RaftCore(RaftPeerSet peers, SwitchDomain switchDomain, GlobalConfig globalConfig, RaftProxy raftProxy,
|
|
||||||
RaftStore raftStore, ClusterVersionJudgement versionJudgement) {
|
|
||||||
this.peers = peers;
|
|
||||||
this.switchDomain = switchDomain;
|
|
||||||
this.globalConfig = globalConfig;
|
|
||||||
this.raftProxy = raftProxy;
|
|
||||||
this.raftStore = raftStore;
|
|
||||||
this.versionJudgement = versionJudgement;
|
|
||||||
this.notifier = new PersistentNotifier(key -> getDatum(key).value);
|
|
||||||
this.publisher = NotifyCenter.registerToPublisher(ValueChangeEvent.class, 16384);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init raft core.
|
* Init raft core.
|
||||||
*
|
*
|
||||||
@ -154,7 +138,11 @@ public class RaftCore implements Closeable {
|
|||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
|
|
||||||
Loggers.RAFT.info("initializing Raft sub-system");
|
Loggers.RAFT.info("initializing Raft sub-system");
|
||||||
|
|
||||||
|
executor.submit(notifier);
|
||||||
|
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
|
|
||||||
raftStore.loadDatums(notifier, datums);
|
raftStore.loadDatums(notifier, datums);
|
||||||
@ -163,32 +151,26 @@ public class RaftCore implements Closeable {
|
|||||||
|
|
||||||
Loggers.RAFT.info("cache loaded, datum count: {}, current term: {}", datums.size(), peers.getTerm());
|
Loggers.RAFT.info("cache loaded, datum count: {}, current term: {}", datums.size(), peers.getTerm());
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (notifier.tasks.size() <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Thread.sleep(1000L);
|
||||||
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
Loggers.RAFT.info("finish to load data from disk, cost: {} ms.", (System.currentTimeMillis() - start));
|
Loggers.RAFT.info("finish to load data from disk, cost: {} ms.", (System.currentTimeMillis() - start));
|
||||||
|
|
||||||
masterTask = GlobalExecutor.registerMasterElection(new MasterElection());
|
GlobalExecutor.registerMasterElection(new MasterElection());
|
||||||
heartbeatTask = GlobalExecutor.registerHeartbeat(new HeartBeat());
|
GlobalExecutor.registerHeartbeat(new HeartBeat());
|
||||||
|
|
||||||
versionJudgement.registerObserver(isAllNewVersion -> {
|
|
||||||
stopWork = isAllNewVersion;
|
|
||||||
if (stopWork) {
|
|
||||||
try {
|
|
||||||
shutdown();
|
|
||||||
} catch (NacosException e) {
|
|
||||||
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
NotifyCenter.registerSubscriber(notifier);
|
|
||||||
|
|
||||||
Loggers.RAFT.info("timer started: leader timeout ms: {}, heart-beat timeout ms: {}",
|
Loggers.RAFT.info("timer started: leader timeout ms: {}, heart-beat timeout ms: {}",
|
||||||
GlobalExecutor.LEADER_TIMEOUT_MS, GlobalExecutor.HEARTBEAT_INTERVAL_MS);
|
GlobalExecutor.LEADER_TIMEOUT_MS, GlobalExecutor.HEARTBEAT_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, ConcurrentHashSet<RecordListener>> getListeners() {
|
public Map<String, List<RecordListener>> getListeners() {
|
||||||
return notifier.getListeners();
|
return listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,9 +181,7 @@ public class RaftCore implements Closeable {
|
|||||||
* @throws Exception any exception during publish
|
* @throws Exception any exception during publish
|
||||||
*/
|
*/
|
||||||
public void signalPublish(String key, Record value) throws Exception {
|
public void signalPublish(String key, Record value) throws Exception {
|
||||||
if (stopWork) {
|
|
||||||
throw new IllegalStateException("old raft protocol already stop work");
|
|
||||||
}
|
|
||||||
if (!isLeader()) {
|
if (!isLeader()) {
|
||||||
ObjectNode params = JacksonUtils.createEmptyJsonNode();
|
ObjectNode params = JacksonUtils.createEmptyJsonNode();
|
||||||
params.put("key", key);
|
params.put("key", key);
|
||||||
@ -215,8 +195,8 @@ public class RaftCore implements Closeable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPERATE_LOCK.lock();
|
|
||||||
try {
|
try {
|
||||||
|
OPERATE_LOCK.lock();
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
final Datum datum = new Datum();
|
final Datum datum = new Datum();
|
||||||
datum.key = key;
|
datum.key = key;
|
||||||
@ -242,23 +222,26 @@ public class RaftCore implements Closeable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String url = buildUrl(server, API_ON_PUB);
|
final String url = buildUrl(server, API_ON_PUB);
|
||||||
HttpClient.asyncHttpPostLarge(url, Arrays.asList("key=" + key), content,
|
HttpClient.asyncHttpPostLarge(url, Arrays.asList("key", key), content, new Callback<String>() {
|
||||||
new AsyncCompletionHandler<Integer>() {
|
|
||||||
@Override
|
@Override
|
||||||
public Integer onCompleted(Response response) throws Exception {
|
public void onReceive(RestResult<String> result) {
|
||||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
Loggers.RAFT
|
Loggers.RAFT
|
||||||
.warn("[RAFT] failed to publish data to peer, datumId={}, peer={}, http code={}",
|
.warn("[RAFT] failed to publish data to peer, datumId={}, peer={}, http code={}",
|
||||||
datum.key, server, response.getStatusCode());
|
datum.key, server, result.getCode());
|
||||||
return 1;
|
return;
|
||||||
}
|
}
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public STATE onContentWriteCompleted() {
|
public void onError(Throwable throwable) {
|
||||||
return STATE.CONTINUE;
|
Loggers.RAFT.error("[RAFT] failed to publish data to peer", throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -284,9 +267,7 @@ public class RaftCore implements Closeable {
|
|||||||
* @throws Exception any exception during delete
|
* @throws Exception any exception during delete
|
||||||
*/
|
*/
|
||||||
public void signalDelete(final String key) throws Exception {
|
public void signalDelete(final String key) throws Exception {
|
||||||
if (stopWork) {
|
|
||||||
throw new IllegalStateException("old raft protocol already stop work");
|
|
||||||
}
|
|
||||||
OPERATE_LOCK.lock();
|
OPERATE_LOCK.lock();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -308,21 +289,29 @@ public class RaftCore implements Closeable {
|
|||||||
|
|
||||||
for (final String server : peers.allServersWithoutMySelf()) {
|
for (final String server : peers.allServersWithoutMySelf()) {
|
||||||
String url = buildUrl(server, API_ON_DEL);
|
String url = buildUrl(server, API_ON_DEL);
|
||||||
HttpClient.asyncHttpDeleteLarge(url, null, json.toString(), new AsyncCompletionHandler<Integer>() {
|
HttpClient.asyncHttpDeleteLarge(url, null, json.toString(), new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer onCompleted(Response response) throws Exception {
|
public void onReceive(RestResult<String> result) {
|
||||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
Loggers.RAFT
|
Loggers.RAFT
|
||||||
.warn("[RAFT] failed to delete data from peer, datumId={}, peer={}, http code={}",
|
.warn("[RAFT] failed to delete data from peer, datumId={}, peer={}, http code={}",
|
||||||
key, server, response.getStatusCode());
|
key, server, result.getCode());
|
||||||
return 1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RaftPeer local = peers.local();
|
RaftPeer local = peers.local();
|
||||||
|
|
||||||
local.resetLeaderDue();
|
local.resetLeaderDue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable throwable) {
|
||||||
|
Loggers.RAFT.error("[RAFT] failed to delete data from peer", throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -339,9 +328,6 @@ public class RaftCore implements Closeable {
|
|||||||
* @throws Exception any exception during publish
|
* @throws Exception any exception during publish
|
||||||
*/
|
*/
|
||||||
public void onPublish(Datum datum, RaftPeer source) throws Exception {
|
public void onPublish(Datum datum, RaftPeer source) throws Exception {
|
||||||
if (stopWork) {
|
|
||||||
throw new IllegalStateException("old raft protocol already stop work");
|
|
||||||
}
|
|
||||||
RaftPeer local = peers.local();
|
RaftPeer local = peers.local();
|
||||||
if (datum.value == null) {
|
if (datum.value == null) {
|
||||||
Loggers.RAFT.warn("received empty datum");
|
Loggers.RAFT.warn("received empty datum");
|
||||||
@ -383,7 +369,9 @@ public class RaftCore implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
raftStore.updateTerm(local.term.get());
|
raftStore.updateTerm(local.term.get());
|
||||||
NotifyCenter.publishEvent(ValueChangeEvent.builder().key(datum.key).action(DataOperation.CHANGE).build());
|
|
||||||
|
notifier.addTask(datum.key, DataOperation.CHANGE);
|
||||||
|
|
||||||
Loggers.RAFT.info("data added/updated, key={}, term={}", datum.key, local.term);
|
Loggers.RAFT.info("data added/updated, key={}, term={}", datum.key, local.term);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,9 +383,7 @@ public class RaftCore implements Closeable {
|
|||||||
* @throws Exception any exception during delete
|
* @throws Exception any exception during delete
|
||||||
*/
|
*/
|
||||||
public void onDelete(String datumKey, RaftPeer source) throws Exception {
|
public void onDelete(String datumKey, RaftPeer source) throws Exception {
|
||||||
if (stopWork) {
|
|
||||||
throw new IllegalStateException("old raft protocol already stop work");
|
|
||||||
}
|
|
||||||
RaftPeer local = peers.local();
|
RaftPeer local = peers.local();
|
||||||
|
|
||||||
if (!peers.isLeader(source.ip)) {
|
if (!peers.isLeader(source.ip)) {
|
||||||
@ -437,30 +423,12 @@ public class RaftCore implements Closeable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdown() throws NacosException {
|
|
||||||
this.stopWork = true;
|
|
||||||
this.raftStore.shutdown();
|
|
||||||
this.peers.shutdown();
|
|
||||||
Loggers.RAFT.warn("start to close old raft protocol!!!");
|
|
||||||
Loggers.RAFT.warn("stop old raft protocol task for notifier");
|
|
||||||
NotifyCenter.deregisterSubscriber(notifier);
|
|
||||||
Loggers.RAFT.warn("stop old raft protocol task for master task");
|
|
||||||
masterTask.cancel(true);
|
|
||||||
Loggers.RAFT.warn("stop old raft protocol task for heartbeat task");
|
|
||||||
heartbeatTask.cancel(true);
|
|
||||||
Loggers.RAFT.warn("clean old cache datum for old raft");
|
|
||||||
datums.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MasterElection implements Runnable {
|
public class MasterElection implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (stopWork) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!peers.isReady()) {
|
if (!peers.isReady()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -500,22 +468,30 @@ public class RaftCore implements Closeable {
|
|||||||
for (final String server : peers.allServersWithoutMySelf()) {
|
for (final String server : peers.allServersWithoutMySelf()) {
|
||||||
final String url = buildUrl(server, API_VOTE);
|
final String url = buildUrl(server, API_VOTE);
|
||||||
try {
|
try {
|
||||||
HttpClient.asyncHttpPost(url, null, params, new AsyncCompletionHandler<Integer>() {
|
HttpClient.asyncHttpPost(url, null, params, new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer onCompleted(Response response) throws Exception {
|
public void onReceive(RestResult<String> result) {
|
||||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
Loggers.RAFT
|
Loggers.RAFT.error("NACOS-RAFT vote failed: {}, url: {}", result.getCode(), url);
|
||||||
.error("NACOS-RAFT vote failed: {}, url: {}", response.getResponseBody(), url);
|
return;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RaftPeer peer = JacksonUtils.toObj(response.getResponseBody(), RaftPeer.class);
|
RaftPeer peer = JacksonUtils.toObj(result.getData(), RaftPeer.class);
|
||||||
|
|
||||||
Loggers.RAFT.info("received approve from peer: {}", JacksonUtils.toJson(peer));
|
Loggers.RAFT.info("received approve from peer: {}", JacksonUtils.toJson(peer));
|
||||||
|
|
||||||
peers.decideLeader(peer);
|
peers.decideLeader(peer);
|
||||||
|
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable throwable) {
|
||||||
|
Loggers.RAFT.error("error while sending vote to server: {}", server, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -532,9 +508,6 @@ public class RaftCore implements Closeable {
|
|||||||
* @return self-peer information
|
* @return self-peer information
|
||||||
*/
|
*/
|
||||||
public synchronized RaftPeer receivedVote(RaftPeer remote) {
|
public synchronized RaftPeer receivedVote(RaftPeer remote) {
|
||||||
if (stopWork) {
|
|
||||||
throw new IllegalStateException("old raft protocol already stop work");
|
|
||||||
}
|
|
||||||
if (!peers.contains(remote)) {
|
if (!peers.contains(remote)) {
|
||||||
throw new IllegalStateException("can not find peer: " + remote.ip);
|
throw new IllegalStateException("can not find peer: " + remote.ip);
|
||||||
}
|
}
|
||||||
@ -567,9 +540,7 @@ public class RaftCore implements Closeable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (stopWork) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!peers.isReady()) {
|
if (!peers.isReady()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -607,7 +578,7 @@ public class RaftCore implements Closeable {
|
|||||||
ArrayNode array = JacksonUtils.createEmptyArrayNode();
|
ArrayNode array = JacksonUtils.createEmptyArrayNode();
|
||||||
|
|
||||||
if (switchDomain.isSendBeatOnly()) {
|
if (switchDomain.isSendBeatOnly()) {
|
||||||
Loggers.RAFT.info("[SEND-BEAT-ONLY] {}", switchDomain.isSendBeatOnly());
|
Loggers.RAFT.info("[SEND-BEAT-ONLY] {}", String.valueOf(switchDomain.isSendBeatOnly()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!switchDomain.isSendBeatOnly()) {
|
if (!switchDomain.isSendBeatOnly()) {
|
||||||
@ -652,28 +623,32 @@ public class RaftCore implements Closeable {
|
|||||||
if (Loggers.RAFT.isDebugEnabled()) {
|
if (Loggers.RAFT.isDebugEnabled()) {
|
||||||
Loggers.RAFT.debug("send beat to server " + server);
|
Loggers.RAFT.debug("send beat to server " + server);
|
||||||
}
|
}
|
||||||
HttpClient.asyncHttpPostLarge(url, null, compressedBytes, new AsyncCompletionHandler<Integer>() {
|
HttpClient.asyncHttpPostLarge(url, null, compressedBytes, new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer onCompleted(Response response) throws Exception {
|
public void onReceive(RestResult<String> result) {
|
||||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
Loggers.RAFT.error("NACOS-RAFT beat failed: {}, peer: {}", response.getResponseBody(),
|
Loggers.RAFT.error("NACOS-RAFT beat failed: {}, peer: {}", result.getCode(), server);
|
||||||
server);
|
|
||||||
MetricsMonitor.getLeaderSendBeatFailedException().increment();
|
MetricsMonitor.getLeaderSendBeatFailedException().increment();
|
||||||
return 1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
peers.update(JacksonUtils.toObj(response.getResponseBody(), RaftPeer.class));
|
peers.update(JacksonUtils.toObj(result.getData(), RaftPeer.class));
|
||||||
if (Loggers.RAFT.isDebugEnabled()) {
|
if (Loggers.RAFT.isDebugEnabled()) {
|
||||||
Loggers.RAFT.debug("receive beat response from: {}", url);
|
Loggers.RAFT.debug("receive beat response from: {}", url);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onThrowable(Throwable t) {
|
public void onError(Throwable throwable) {
|
||||||
Loggers.RAFT.error("NACOS-RAFT error while sending heart-beat to peer: {} {}", server, t);
|
Loggers.RAFT.error("NACOS-RAFT error while sending heart-beat to peer: {} {}", server,
|
||||||
|
throwable);
|
||||||
MetricsMonitor.getLeaderSendBeatFailedException().increment();
|
MetricsMonitor.getLeaderSendBeatFailedException().increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Loggers.RAFT.error("error while sending heart-beat to peer: {} {}", server, e);
|
Loggers.RAFT.error("error while sending heart-beat to peer: {} {}", server, e);
|
||||||
@ -692,9 +667,6 @@ public class RaftCore implements Closeable {
|
|||||||
* @throws Exception any exception during handle
|
* @throws Exception any exception during handle
|
||||||
*/
|
*/
|
||||||
public RaftPeer receivedBeat(JsonNode beat) throws Exception {
|
public RaftPeer receivedBeat(JsonNode beat) throws Exception {
|
||||||
if (stopWork) {
|
|
||||||
throw new IllegalStateException("old raft protocol already stop work");
|
|
||||||
}
|
|
||||||
final RaftPeer local = peers.local();
|
final RaftPeer local = peers.local();
|
||||||
final RaftPeer remote = new RaftPeer();
|
final RaftPeer remote = new RaftPeer();
|
||||||
JsonNode peer = beat.get("peer");
|
JsonNode peer = beat.get("peer");
|
||||||
@ -796,15 +768,15 @@ public class RaftCore implements Closeable {
|
|||||||
|
|
||||||
// update datum entry
|
// update datum entry
|
||||||
String url = buildUrl(remote.ip, API_GET) + "?keys=" + URLEncoder.encode(keys, "UTF-8");
|
String url = buildUrl(remote.ip, API_GET) + "?keys=" + URLEncoder.encode(keys, "UTF-8");
|
||||||
HttpClient.asyncHttpGet(url, null, null, new AsyncCompletionHandler<Integer>() {
|
HttpClient.asyncHttpGet(url, null, null, new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer onCompleted(Response response) throws Exception {
|
public void onReceive(RestResult<String> result) {
|
||||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
return 1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JsonNode> datumList = JacksonUtils
|
List<JsonNode> datumList = JacksonUtils
|
||||||
.toObj(response.getResponseBody(), new TypeReference<List<JsonNode>>() {
|
.toObj(result.getData(), new TypeReference<List<JsonNode>>() {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (JsonNode datumJson : datumList) {
|
for (JsonNode datumJson : datumList) {
|
||||||
@ -849,10 +821,7 @@ public class RaftCore implements Closeable {
|
|||||||
raftStore.write(newDatum);
|
raftStore.write(newDatum);
|
||||||
|
|
||||||
datums.put(newDatum.key, newDatum);
|
datums.put(newDatum.key, newDatum);
|
||||||
|
notifier.addTask(newDatum.key, DataOperation.CHANGE);
|
||||||
NotifyCenter.publishEvent(
|
|
||||||
ValueChangeEvent.builder().key(newDatum.key).action(DataOperation.CHANGE)
|
|
||||||
.build());
|
|
||||||
|
|
||||||
local.resetLeaderDue();
|
local.resetLeaderDue();
|
||||||
|
|
||||||
@ -876,9 +845,24 @@ public class RaftCore implements Closeable {
|
|||||||
OPERATE_LOCK.unlock();
|
OPERATE_LOCK.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
TimeUnit.MILLISECONDS.sleep(200);
|
TimeUnit.MILLISECONDS.sleep(200);
|
||||||
return 0;
|
} catch (InterruptedException e) {
|
||||||
|
Loggers.RAFT.error("[RAFT-BEAT] Interrupted error ", e);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable throwable) {
|
||||||
|
Loggers.RAFT.error("[RAFT-BEAT] failed to sync datum from leader", throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
batch.clear();
|
batch.clear();
|
||||||
@ -916,9 +900,21 @@ public class RaftCore implements Closeable {
|
|||||||
* @param listener new listener
|
* @param listener new listener
|
||||||
*/
|
*/
|
||||||
public void listen(String key, RecordListener listener) {
|
public void listen(String key, RecordListener listener) {
|
||||||
notifier.registerListener(key, listener);
|
|
||||||
|
List<RecordListener> listenerList = listeners.get(key);
|
||||||
|
if (listenerList != null && listenerList.contains(listener)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listenerList == null) {
|
||||||
|
listenerList = new CopyOnWriteArrayList<>();
|
||||||
|
listeners.put(key, listenerList);
|
||||||
|
}
|
||||||
|
|
||||||
Loggers.RAFT.info("add listener: {}", key);
|
Loggers.RAFT.info("add listener: {}", key);
|
||||||
|
|
||||||
|
listenerList.add(listener);
|
||||||
|
|
||||||
// if data present, notify immediately
|
// if data present, notify immediately
|
||||||
for (Datum datum : datums.values()) {
|
for (Datum datum : datums.values()) {
|
||||||
if (!listener.interests(datum.key)) {
|
if (!listener.interests(datum.key)) {
|
||||||
@ -940,11 +936,22 @@ public class RaftCore implements Closeable {
|
|||||||
* @param listener listener
|
* @param listener listener
|
||||||
*/
|
*/
|
||||||
public void unListen(String key, RecordListener listener) {
|
public void unListen(String key, RecordListener listener) {
|
||||||
notifier.deregisterListener(key, listener);
|
|
||||||
|
if (!listeners.containsKey(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (RecordListener dl : listeners.get(key)) {
|
||||||
|
// TODO maybe use equal:
|
||||||
|
if (dl == listener) {
|
||||||
|
listeners.get(key).remove(listener);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unlistenAll(String key) {
|
public void unlistenAll(String key) {
|
||||||
notifier.deregisterAllListener(key);
|
listeners.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTerm(long term) {
|
public void setTerm(long term) {
|
||||||
@ -999,7 +1006,7 @@ public class RaftCore implements Closeable {
|
|||||||
|
|
||||||
public void addDatum(Datum datum) {
|
public void addDatum(Datum datum) {
|
||||||
datums.put(datum.key, datum);
|
datums.put(datum.key, datum);
|
||||||
NotifyCenter.publishEvent(ValueChangeEvent.builder().key(datum.key).action(DataOperation.CHANGE).build());
|
notifier.addTask(datum.key, DataOperation.CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1028,9 +1035,7 @@ public class RaftCore implements Closeable {
|
|||||||
raftStore.delete(deleted);
|
raftStore.delete(deleted);
|
||||||
Loggers.RAFT.info("datum deleted, key: {}", key);
|
Loggers.RAFT.info("datum deleted, key: {}", key);
|
||||||
}
|
}
|
||||||
NotifyCenter.publishEvent(
|
notifier.addTask(URLDecoder.decode(key, "UTF-8"), DataOperation.DELETE);
|
||||||
ValueChangeEvent.builder().key(URLDecoder.decode(key, "UTF-8")).action(DataOperation.DELETE)
|
|
||||||
.build());
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
Loggers.RAFT.warn("datum key decode failed: {}", key);
|
Loggers.RAFT.warn("datum key decode failed: {}", key);
|
||||||
}
|
}
|
||||||
@ -1040,9 +1045,115 @@ public class RaftCore implements Closeable {
|
|||||||
return initialized || !globalConfig.isDataWarmup();
|
return initialized || !globalConfig.isDataWarmup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public int getNotifyTaskCount() {
|
public int getNotifyTaskCount() {
|
||||||
return (int) publisher.currentEventSize();
|
return notifier.getTaskSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Notifier implements Runnable {
|
||||||
|
|
||||||
|
private ConcurrentHashMap<String, String> services = new ConcurrentHashMap<>(10 * 1024);
|
||||||
|
|
||||||
|
private BlockingQueue<Pair> tasks = new LinkedBlockingQueue<>(1024 * 1024);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add notify task.
|
||||||
|
*
|
||||||
|
* @param datumKey datum key
|
||||||
|
* @param action action of datum
|
||||||
|
*/
|
||||||
|
public void addTask(String datumKey, DataOperation action) {
|
||||||
|
|
||||||
|
if (services.containsKey(datumKey) && action == DataOperation.CHANGE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (action == DataOperation.CHANGE) {
|
||||||
|
services.put(datumKey, StringUtils.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loggers.RAFT.info("add task {}", datumKey);
|
||||||
|
|
||||||
|
tasks.add(Pair.with(datumKey, action));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTaskSize() {
|
||||||
|
return tasks.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Loggers.RAFT.info("raft notifier started");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
Pair pair = tasks.take();
|
||||||
|
|
||||||
|
if (pair == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String datumKey = (String) pair.getValue0();
|
||||||
|
DataOperation action = (DataOperation) pair.getValue1();
|
||||||
|
|
||||||
|
services.remove(datumKey);
|
||||||
|
|
||||||
|
Loggers.RAFT.info("remove task {}", datumKey);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (listeners.containsKey(KeyBuilder.SERVICE_META_KEY_PREFIX)) {
|
||||||
|
|
||||||
|
if (KeyBuilder.matchServiceMetaKey(datumKey) && !KeyBuilder.matchSwitchKey(datumKey)) {
|
||||||
|
|
||||||
|
for (RecordListener listener : listeners.get(KeyBuilder.SERVICE_META_KEY_PREFIX)) {
|
||||||
|
try {
|
||||||
|
if (action == DataOperation.CHANGE) {
|
||||||
|
listener.onChange(datumKey, getDatum(datumKey).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == DataOperation.DELETE) {
|
||||||
|
listener.onDelete(datumKey);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Loggers.RAFT
|
||||||
|
.error("[NACOS-RAFT] error while notifying listener of key: {}", datumKey,
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!listeners.containsKey(datumKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (RecordListener listener : listeners.get(datumKey)) {
|
||||||
|
|
||||||
|
count++;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (action == DataOperation.CHANGE) {
|
||||||
|
listener.onChange(datumKey, getDatum(datumKey).value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == DataOperation.DELETE) {
|
||||||
|
listener.onDelete(datumKey);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {}", datumKey, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Loggers.RAFT.isDebugEnabled()) {
|
||||||
|
Loggers.RAFT.debug("[NACOS-RAFT] datum change notified, key: {}, listener count: {}", datumKey,
|
||||||
|
count);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Loggers.RAFT.error("[NACOS-RAFT] Error while handling notifying task", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,20 +16,18 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.naming.consistency.persistent.raft;
|
package com.alibaba.nacos.naming.consistency.persistent.raft;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.common.http.Callback;
|
||||||
import com.alibaba.nacos.common.lifecycle.Closeable;
|
import com.alibaba.nacos.common.model.RestResult;
|
||||||
import com.alibaba.nacos.common.notify.NotifyCenter;
|
import com.alibaba.nacos.common.notify.NotifyCenter;
|
||||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||||
import com.alibaba.nacos.core.cluster.Member;
|
import com.alibaba.nacos.core.cluster.Member;
|
||||||
import com.alibaba.nacos.core.cluster.MemberChangeListener;
|
import com.alibaba.nacos.core.cluster.MemberChangeListener;
|
||||||
import com.alibaba.nacos.core.cluster.MembersChangeEvent;
|
import com.alibaba.nacos.core.cluster.MembersChangeEvent;
|
||||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
import com.alibaba.nacos.naming.misc.HttpClient;
|
import com.alibaba.nacos.naming.misc.HttpClient;
|
||||||
import com.alibaba.nacos.naming.misc.Loggers;
|
import com.alibaba.nacos.naming.misc.Loggers;
|
||||||
import com.alibaba.nacos.naming.misc.NetUtils;
|
import com.alibaba.nacos.naming.misc.NetUtils;
|
||||||
import com.ning.http.client.AsyncCompletionHandler;
|
|
||||||
import com.ning.http.client.Response;
|
|
||||||
import org.apache.commons.collections.SortedBag;
|
import org.apache.commons.collections.SortedBag;
|
||||||
import org.apache.commons.collections.bag.TreeBag;
|
import org.apache.commons.collections.bag.TreeBag;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -37,7 +35,6 @@ import org.springframework.context.annotation.DependsOn;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -51,13 +48,11 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
/**
|
/**
|
||||||
* Sets of raft peers.
|
* Sets of raft peers.
|
||||||
*
|
*
|
||||||
* @deprecated will remove in 1.4.x
|
|
||||||
* @author nacos
|
* @author nacos
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@Component
|
@Component
|
||||||
@DependsOn("ProtocolManager")
|
@DependsOn("ProtocolManager")
|
||||||
public class RaftPeerSet extends MemberChangeListener implements Closeable {
|
public class RaftPeerSet extends MemberChangeListener {
|
||||||
|
|
||||||
private final ServerMemberManager memberManager;
|
private final ServerMemberManager memberManager;
|
||||||
|
|
||||||
@ -71,7 +66,7 @@ public class RaftPeerSet extends MemberChangeListener implements Closeable {
|
|||||||
|
|
||||||
private volatile boolean ready = false;
|
private volatile boolean ready = false;
|
||||||
|
|
||||||
private Set<Member> oldMembers = new HashSet<>();
|
private Set<Member> oldMembers;
|
||||||
|
|
||||||
public RaftPeerSet(ServerMemberManager memberManager) {
|
public RaftPeerSet(ServerMemberManager memberManager) {
|
||||||
this.memberManager = memberManager;
|
this.memberManager = memberManager;
|
||||||
@ -83,16 +78,6 @@ public class RaftPeerSet extends MemberChangeListener implements Closeable {
|
|||||||
changePeers(memberManager.allMembers());
|
changePeers(memberManager.allMembers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdown() throws NacosException {
|
|
||||||
this.localTerm.set(-1);
|
|
||||||
this.leader = null;
|
|
||||||
this.peers.clear();
|
|
||||||
this.sites.clear();
|
|
||||||
this.ready = false;
|
|
||||||
this.oldMembers.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RaftPeer getLeader() {
|
public RaftPeer getLeader() {
|
||||||
if (ApplicationUtils.getStandaloneMode()) {
|
if (ApplicationUtils.getStandaloneMode()) {
|
||||||
return local();
|
return local();
|
||||||
@ -233,20 +218,28 @@ public class RaftPeerSet extends MemberChangeListener implements Closeable {
|
|||||||
if (!Objects.equals(peer, candidate) && peer.state == RaftPeer.State.LEADER) {
|
if (!Objects.equals(peer, candidate) && peer.state == RaftPeer.State.LEADER) {
|
||||||
try {
|
try {
|
||||||
String url = RaftCore.buildUrl(peer.ip, RaftCore.API_GET_PEER);
|
String url = RaftCore.buildUrl(peer.ip, RaftCore.API_GET_PEER);
|
||||||
HttpClient.asyncHttpGet(url, null, params, new AsyncCompletionHandler<Integer>() {
|
HttpClient.asyncHttpGet(url, null, params, new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer onCompleted(Response response) throws Exception {
|
public void onReceive(RestResult<String> result) {
|
||||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
Loggers.RAFT
|
Loggers.RAFT
|
||||||
.error("[NACOS-RAFT] get peer failed: {}, peer: {}", response.getResponseBody(),
|
.error("[NACOS-RAFT] get peer failed: {}, peer: {}", result.getCode(),
|
||||||
peer.ip);
|
peer.ip);
|
||||||
peer.state = RaftPeer.State.FOLLOWER;
|
peer.state = RaftPeer.State.FOLLOWER;
|
||||||
return 1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(JacksonUtils.toObj(response.getResponseBody(), RaftPeer.class));
|
update(JacksonUtils.toObj(result.getData(), RaftPeer.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable throwable) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -317,7 +310,7 @@ public class RaftPeerSet extends MemberChangeListener implements Closeable {
|
|||||||
@Override
|
@Override
|
||||||
public void onEvent(MembersChangeEvent event) {
|
public void onEvent(MembersChangeEvent event) {
|
||||||
Collection<Member> members = event.getMembers();
|
Collection<Member> members = event.getMembers();
|
||||||
if (oldMembers.isEmpty()) {
|
if (oldMembers == null) {
|
||||||
oldMembers = new HashSet<>(members);
|
oldMembers = new HashSet<>(members);
|
||||||
} else {
|
} else {
|
||||||
oldMembers.removeAll(members);
|
oldMembers.removeAll(members);
|
||||||
@ -365,6 +358,4 @@ public class RaftPeerSet extends MemberChangeListener implements Closeable {
|
|||||||
return "RaftPeerSet{" + "localTerm=" + localTerm + ", leader=" + leader + ", peers=" + peers + ", sites="
|
return "RaftPeerSet{" + "localTerm=" + localTerm + ", leader=" + leader + ", peers=" + peers + ", sites="
|
||||||
+ sites + '}';
|
+ sites + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.naming.consistency.persistent.raft;
|
package com.alibaba.nacos.naming.consistency.persistent.raft;
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||||
|
import com.alibaba.nacos.common.model.RestResult;
|
||||||
import com.alibaba.nacos.naming.misc.HttpClient;
|
import com.alibaba.nacos.naming.misc.HttpClient;
|
||||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,9 +50,9 @@ public class RaftProxy {
|
|||||||
}
|
}
|
||||||
String url = "http://" + server + ApplicationUtils.getContextPath() + api;
|
String url = "http://" + server + ApplicationUtils.getContextPath() + api;
|
||||||
|
|
||||||
HttpClient.HttpResult result = HttpClient.httpGet(url, null, params);
|
RestResult<String> result = HttpClient.httpGet(url, null, params);
|
||||||
if (result.code != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
throw new IllegalStateException("leader failed, caused by: " + result.content);
|
throw new IllegalStateException("leader failed, caused by: " + result.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ public class RaftProxy {
|
|||||||
server = server + UtilsAndCommons.IP_PORT_SPLITER + ApplicationUtils.getPort();
|
server = server + UtilsAndCommons.IP_PORT_SPLITER + ApplicationUtils.getPort();
|
||||||
}
|
}
|
||||||
String url = "http://" + server + ApplicationUtils.getContextPath() + api;
|
String url = "http://" + server + ApplicationUtils.getContextPath() + api;
|
||||||
HttpClient.HttpResult result;
|
RestResult<String> result;
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case GET:
|
case GET:
|
||||||
result = HttpClient.httpGet(url, null, params);
|
result = HttpClient.httpGet(url, null, params);
|
||||||
@ -86,8 +86,8 @@ public class RaftProxy {
|
|||||||
throw new RuntimeException("unsupported method:" + method);
|
throw new RuntimeException("unsupported method:" + method);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.code != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
throw new IllegalStateException("leader failed, caused by: " + result.content);
|
throw new IllegalStateException("leader failed, caused by: " + result.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,9 +108,9 @@ public class RaftProxy {
|
|||||||
}
|
}
|
||||||
String url = "http://" + server + ApplicationUtils.getContextPath() + api;
|
String url = "http://" + server + ApplicationUtils.getContextPath() + api;
|
||||||
|
|
||||||
HttpClient.HttpResult result = HttpClient.httpPostLarge(url, headers, content);
|
RestResult<String> result = HttpClient.httpPostLarge(url, headers, content);
|
||||||
if (result.code != HttpURLConnection.HTTP_OK) {
|
if (!result.ok()) {
|
||||||
throw new IllegalStateException("leader failed, caused by: " + result.content);
|
throw new IllegalStateException("leader failed, caused by: " + result.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ public class ApiController extends InstanceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(domSet)) {
|
if (CollectionUtils.isEmpty(domSet)) {
|
||||||
result.put("doms", JacksonUtils.transferToJsonNode(new HashSet<>()));
|
|
||||||
result.put("count", 0);
|
result.put("count", 0);
|
||||||
|
result.set("doms", JacksonUtils.transferToJsonNode(new HashSet<>()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +99,8 @@ public class ApiController extends InstanceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.put("doms", JacksonUtils.transferToJsonNode(doms));
|
|
||||||
result.put("count", doms.size());
|
result.put("count", doms.size());
|
||||||
|
result.set("doms", JacksonUtils.transferToJsonNode(doms));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +116,8 @@ public class ApiController extends InstanceController {
|
|||||||
count += doms.get(namespaceId).size();
|
count += doms.get(namespaceId).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
result.put("doms", JacksonUtils.transferToJsonNode(doms));
|
|
||||||
result.put("count", count);
|
result.put("count", count);
|
||||||
|
result.set("doms", JacksonUtils.transferToJsonNode(doms));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user