[code quality] [nacos-client] [naming] simple the judge logic, constant export (#6009)
This commit is contained in:
parent
43f4d5d927
commit
79be070e1b
@ -52,6 +52,12 @@ import java.util.Properties;
|
||||
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
||||
public class NacosNamingService implements NamingService {
|
||||
|
||||
private static final String DEFAULT_NAMING_LOG_FILE_PATH = "naming.log";
|
||||
|
||||
private static final String UP = "UP";
|
||||
|
||||
private static final String DOWN = "DOWN";
|
||||
|
||||
/**
|
||||
* Each Naming service should have different namespace.
|
||||
*/
|
||||
@ -97,7 +103,7 @@ public class NacosNamingService implements NamingService {
|
||||
.isNotEmpty(properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME))) {
|
||||
logName = properties.getProperty(UtilAndComs.NACOS_NAMING_LOG_NAME);
|
||||
} else {
|
||||
logName = "naming.log";
|
||||
logName = DEFAULT_NAMING_LOG_FILE_PATH;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -441,7 +447,7 @@ public class NacosNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public String getServerStatus() {
|
||||
return clientProxy.serverHealthy() ? "UP" : "DOWN";
|
||||
return clientProxy.serverHealthy() ? UP : DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,6 +52,20 @@ import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
*/
|
||||
public class FailoverReactor implements Closeable {
|
||||
|
||||
private static final String FAILOVER_DIR = "/failover";
|
||||
|
||||
private static final String IS_FAILOVER_MODE = "1";
|
||||
|
||||
private static final String NO_FAILOVER_MODE = "0";
|
||||
|
||||
private static final String FAILOVER_MODE_PARAM = "failover-mode";
|
||||
|
||||
private Map<String, ServiceInfo> serviceMap = new ConcurrentHashMap<String, ServiceInfo>();
|
||||
|
||||
private final Map<String, String> switchParams = new ConcurrentHashMap<String, String>();
|
||||
|
||||
private static final long DAY_PERIOD_MINUTES = 24 * 60;
|
||||
|
||||
private final String failoverDir;
|
||||
|
||||
private final ServiceInfoHolder serviceInfoHolder;
|
||||
@ -60,7 +74,7 @@ public class FailoverReactor implements Closeable {
|
||||
|
||||
public FailoverReactor(ServiceInfoHolder serviceInfoHolder, String cacheDir) {
|
||||
this.serviceInfoHolder = serviceInfoHolder;
|
||||
this.failoverDir = cacheDir + "/failover";
|
||||
this.failoverDir = cacheDir + FAILOVER_DIR;
|
||||
// init executorService
|
||||
this.executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||
@Override
|
||||
@ -74,12 +88,6 @@ public class FailoverReactor implements Closeable {
|
||||
this.init();
|
||||
}
|
||||
|
||||
private Map<String, ServiceInfo> serviceMap = new ConcurrentHashMap<String, ServiceInfo>();
|
||||
|
||||
private final Map<String, String> switchParams = new ConcurrentHashMap<String, String>();
|
||||
|
||||
private static final long DAY_PERIOD_MINUTES = 24 * 60;
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
@ -159,17 +167,17 @@ public class FailoverReactor implements Closeable {
|
||||
|
||||
for (String line : lines) {
|
||||
String line1 = line.trim();
|
||||
if ("1".equals(line1)) {
|
||||
switchParams.put("failover-mode", "true");
|
||||
if (IS_FAILOVER_MODE.equals(line1)) {
|
||||
switchParams.put(FAILOVER_MODE_PARAM, Boolean.TRUE.toString());
|
||||
NAMING_LOGGER.info("failover-mode is on");
|
||||
new FailoverFileReader().run();
|
||||
} else if ("0".equals(line1)) {
|
||||
switchParams.put("failover-mode", "false");
|
||||
} else if (NO_FAILOVER_MODE.equals(line1)) {
|
||||
switchParams.put(FAILOVER_MODE_PARAM, Boolean.FALSE.toString());
|
||||
NAMING_LOGGER.info("failover-mode is off");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switchParams.put("failover-mode", "false");
|
||||
switchParams.put(FAILOVER_MODE_PARAM, Boolean.FALSE.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,9 +265,9 @@ public class FailoverReactor implements Closeable {
|
||||
ServiceInfo serviceInfo = entry.getValue();
|
||||
if (StringUtils.equals(serviceInfo.getKey(), UtilAndComs.ALL_IPS) || StringUtils
|
||||
.equals(serviceInfo.getName(), UtilAndComs.ENV_LIST_KEY) || StringUtils
|
||||
.equals(serviceInfo.getName(), "00-00---000-ENV_CONFIGS-000---00-00") || StringUtils
|
||||
.equals(serviceInfo.getName(), "vipclient.properties") || StringUtils
|
||||
.equals(serviceInfo.getName(), "00-00---000-ALL_HOSTS-000---00-00")) {
|
||||
.equals(serviceInfo.getName(), UtilAndComs.ENV_CONFIGS) || StringUtils
|
||||
.equals(serviceInfo.getName(), UtilAndComs.VIP_CLIENT_FILE) || StringUtils
|
||||
.equals(serviceInfo.getName(), UtilAndComs.ALL_HOSTS)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -269,7 +277,7 @@ public class FailoverReactor implements Closeable {
|
||||
}
|
||||
|
||||
public boolean isFailoverSwitch() {
|
||||
return Boolean.parseBoolean(switchParams.get("failover-mode"));
|
||||
return Boolean.parseBoolean(switchParams.get(FAILOVER_MODE_PARAM));
|
||||
}
|
||||
|
||||
public ServiceInfo getService(String key) {
|
||||
|
@ -49,6 +49,8 @@ import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
*/
|
||||
public class BeatReactor implements Closeable {
|
||||
|
||||
private static final String CLIENT_BEAT_INTERVAL_FIELD = "clientBeatInterval";
|
||||
|
||||
private final ScheduledExecutorService executorService;
|
||||
|
||||
private final NamingHttpClientProxy serverProxy;
|
||||
@ -93,7 +95,7 @@ public class BeatReactor implements Closeable {
|
||||
public void addBeatInfo(String serviceName, BeatInfo beatInfo) {
|
||||
NAMING_LOGGER.info("[BEAT] adding beat: {} to beat map.", beatInfo);
|
||||
String key = buildKey(serviceName, beatInfo.getIp(), beatInfo.getPort());
|
||||
BeatInfo existBeat = null;
|
||||
BeatInfo existBeat;
|
||||
//fix #1733
|
||||
if ((existBeat = dom2Beat.remove(key)) != null) {
|
||||
existBeat.setStopped(true);
|
||||
@ -178,7 +180,7 @@ public class BeatReactor implements Closeable {
|
||||
long nextTime = beatInfo.getPeriod();
|
||||
try {
|
||||
JsonNode result = serverProxy.sendBeat(beatInfo, BeatReactor.this.lightBeatEnabled);
|
||||
long interval = result.get("clientBeatInterval").asLong();
|
||||
long interval = result.get(CLIENT_BEAT_INTERVAL_FIELD).asLong();
|
||||
boolean lightBeatEnabled = false;
|
||||
if (result.has(CommonParams.LIGHT_BEAT_ENABLED)) {
|
||||
lightBeatEnabled = result.get(CommonParams.LIGHT_BEAT_ENABLED).asBoolean();
|
||||
|
@ -38,6 +38,14 @@ import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
*/
|
||||
public class ConcurrentDiskUtil {
|
||||
|
||||
private static final String READ_ONLY = "r";
|
||||
|
||||
private static final String READ_WRITE = "rw";
|
||||
|
||||
private static final int RETRY_COUNT = 10;
|
||||
|
||||
private static final int SLEEP_BASETIME = 10;
|
||||
|
||||
/**
|
||||
* get file content.
|
||||
*
|
||||
@ -63,7 +71,7 @@ public class ConcurrentDiskUtil {
|
||||
RandomAccessFile fis = null;
|
||||
FileLock rlock = null;
|
||||
try {
|
||||
fis = new RandomAccessFile(file, "r");
|
||||
fis = new RandomAccessFile(file, READ_ONLY);
|
||||
FileChannel fcin = fis.getChannel();
|
||||
int i = 0;
|
||||
do {
|
||||
@ -128,7 +136,7 @@ public class ConcurrentDiskUtil {
|
||||
FileLock lock = null;
|
||||
RandomAccessFile raf = null;
|
||||
try {
|
||||
raf = new RandomAccessFile(file, "rw");
|
||||
raf = new RandomAccessFile(file, READ_WRITE);
|
||||
channel = raf.getChannel();
|
||||
int i = 0;
|
||||
do {
|
||||
@ -192,12 +200,9 @@ public class ConcurrentDiskUtil {
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
public static String byteBufferToString(ByteBuffer buffer, String charsetName) throws IOException {
|
||||
Charset charset = null;
|
||||
CharsetDecoder decoder = null;
|
||||
CharBuffer charBuffer = null;
|
||||
charset = Charset.forName(charsetName);
|
||||
decoder = charset.newDecoder();
|
||||
charBuffer = decoder.decode(buffer.asReadOnlyBuffer());
|
||||
Charset charset = Charset.forName(charsetName);
|
||||
CharsetDecoder decoder = charset.newDecoder();
|
||||
CharBuffer charBuffer = decoder.decode(buffer.asReadOnlyBuffer());
|
||||
return charBuffer.toString();
|
||||
}
|
||||
|
||||
@ -209,7 +214,4 @@ public class ConcurrentDiskUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int RETRY_COUNT = 10;
|
||||
|
||||
private static final int SLEEP_BASETIME = 10;
|
||||
}
|
||||
|
@ -50,6 +50,14 @@ import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
*/
|
||||
public class ServiceInfoHolder implements Closeable {
|
||||
|
||||
private static final String JM_SNAPSHOT_PATH_PROPERTY = "JM.SNAPSHOT.PATH";
|
||||
|
||||
private static final String FILE_PATH_NACOS = "nacos";
|
||||
|
||||
private static final String FILE_PATH_NAMING = "naming";
|
||||
|
||||
private static final String USER_HOME_PROPERTY = "user.home";
|
||||
|
||||
private final ConcurrentMap<String, ServiceInfo> serviceInfoMap;
|
||||
|
||||
private final FailoverReactor failoverReactor;
|
||||
@ -70,7 +78,7 @@ public class ServiceInfoHolder implements Closeable {
|
||||
}
|
||||
|
||||
private void initCacheDir(String namespace, Properties properties) {
|
||||
String jmSnapshotPath = System.getProperty("JM.SNAPSHOT.PATH");
|
||||
String jmSnapshotPath = System.getProperty(JM_SNAPSHOT_PATH_PROPERTY);
|
||||
|
||||
String namingCacheRegistryDir = "";
|
||||
if (properties.getProperty(PropertyKeyConst.NAMING_CACHE_REGISTRY_DIR) != null) {
|
||||
@ -78,11 +86,11 @@ public class ServiceInfoHolder implements Closeable {
|
||||
}
|
||||
|
||||
if (!StringUtils.isBlank(jmSnapshotPath)) {
|
||||
cacheDir = jmSnapshotPath + File.separator + "nacos" + namingCacheRegistryDir
|
||||
+ File.separator + "naming" + File.separator + namespace;
|
||||
cacheDir = jmSnapshotPath + File.separator + FILE_PATH_NACOS + namingCacheRegistryDir
|
||||
+ File.separator + FILE_PATH_NAMING + File.separator + namespace;
|
||||
} else {
|
||||
cacheDir = System.getProperty("user.home") + File.separator + "nacos" + namingCacheRegistryDir
|
||||
+ File.separator + "naming" + File.separator + namespace;
|
||||
cacheDir = System.getProperty(USER_HOME_PROPERTY) + File.separator + FILE_PATH_NACOS + namingCacheRegistryDir
|
||||
+ File.separator + FILE_PATH_NAMING + File.separator + namespace;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
@ -42,10 +43,16 @@ import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
*/
|
||||
public class PushReceiver implements Runnable, Closeable {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
private static final Charset UTF_8 = StandardCharsets.UTF_8;
|
||||
|
||||
private static final int UDP_MSS = 64 * 1024;
|
||||
|
||||
private static final String PUSH_PACKAGE_TYPE_DOM = "dom";
|
||||
|
||||
private static final String PUSH_PACKAGE_TYPE_SERVICE = "service";
|
||||
|
||||
private static final String PUSH_PACKAGE_TYPE_DUMP = "dump";
|
||||
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
private DatagramSocket udpSocket;
|
||||
@ -99,13 +106,13 @@ public class PushReceiver implements Runnable, Closeable {
|
||||
|
||||
PushPacket pushPacket = JacksonUtils.toObj(json, PushPacket.class);
|
||||
String ack;
|
||||
if ("dom".equals(pushPacket.type) || "service".equals(pushPacket.type)) {
|
||||
if (PUSH_PACKAGE_TYPE_DOM.equals(pushPacket.type) || PUSH_PACKAGE_TYPE_SERVICE.equals(pushPacket.type)) {
|
||||
serviceInfoHolder.processServiceInfo(pushPacket.data);
|
||||
|
||||
// send ack to server
|
||||
ack = "{\"type\": \"push-ack\"" + ", \"lastRefTime\":\"" + pushPacket.lastRefTime + "\", \"data\":"
|
||||
+ "\"\"}";
|
||||
} else if ("dump".equals(pushPacket.type)) {
|
||||
} else if (PUSH_PACKAGE_TYPE_DUMP.equals(pushPacket.type)) {
|
||||
// dump data to server
|
||||
ack = "{\"type\": \"dump-ack\"" + ", \"lastRefTime\": \"" + pushPacket.lastRefTime + "\", \"data\":"
|
||||
+ "\"" + StringUtils.escapeJavaScript(JacksonUtils.toJson(serviceInfoHolder.getServiceInfoMap()))
|
||||
|
@ -41,6 +41,16 @@ import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||
public abstract class AbstractNamingClientProxy extends Subscriber<ServerListChangedEvent>
|
||||
implements NamingClientProxy {
|
||||
|
||||
private static final String APP_FILED = "app";
|
||||
|
||||
private static final String SIGNATURE_FILED = "signature";
|
||||
|
||||
private static final String DATA_FILED = "data";
|
||||
|
||||
private static final String AK_FILED = "ak";
|
||||
|
||||
private static final String SEPARATOR = "@@";
|
||||
|
||||
private final SecurityProxy securityProxy;
|
||||
|
||||
private final Properties properties;
|
||||
@ -73,14 +83,14 @@ public abstract class AbstractNamingClientProxy extends Subscriber<ServerListCha
|
||||
Map<String, String> result = new HashMap<>(2);
|
||||
String ak = getAccessKey();
|
||||
String sk = getSecretKey();
|
||||
result.put("app", AppNameUtils.getAppName());
|
||||
result.put(APP_FILED, AppNameUtils.getAppName());
|
||||
if (StringUtils.isNotBlank(ak) && StringUtils.isNotBlank(sk)) {
|
||||
try {
|
||||
String signData = getSignData(serviceName);
|
||||
String signature = SignUtil.sign(signData, sk);
|
||||
result.put("signature", signature);
|
||||
result.put("data", signData);
|
||||
result.put("ak", ak);
|
||||
result.put(SIGNATURE_FILED, signature);
|
||||
result.put(DATA_FILED, signData);
|
||||
result.put(AK_FILED, ak);
|
||||
} catch (Exception e) {
|
||||
NAMING_LOGGER.error("inject ak/sk failed.", e);
|
||||
}
|
||||
@ -105,7 +115,7 @@ public abstract class AbstractNamingClientProxy extends Subscriber<ServerListCha
|
||||
}
|
||||
|
||||
private String getSignData(String serviceName) {
|
||||
return StringUtils.isNotEmpty(serviceName) ? System.currentTimeMillis() + "@@" + serviceName
|
||||
return StringUtils.isNotEmpty(serviceName) ? System.currentTimeMillis() + SEPARATOR + serviceName
|
||||
: String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,34 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
|
||||
private static final int DEFAULT_SERVER_PORT = 8848;
|
||||
|
||||
private static final String IP_PARAM = "ip";
|
||||
|
||||
private static final String PORT_PARAM = "port";
|
||||
|
||||
private static final String WEIGHT_PARAM = "weight";
|
||||
|
||||
private static final String ENABLE_PARAM = "enabled";
|
||||
|
||||
private static final String EPHEMERAL_PARAM = "ephemeral";
|
||||
|
||||
private static final String META_PARAM = "metadata";
|
||||
|
||||
private static final String SELECTOR_PARAM = "selector";
|
||||
|
||||
private static final String HEALTHY_PARAM = "healthy";
|
||||
|
||||
private static final String PROTECT_THRESHOLD_PARAM = "protectThreshold";
|
||||
|
||||
private static final String CLUSTERS_PARAM = "clusters";
|
||||
|
||||
private static final String UDP_PORT_PARAM = "udpPort";
|
||||
|
||||
private static final String CLIENT_IP_PARAM = "clientIP";
|
||||
|
||||
private static final String HEALTHY_ONLY_PARAM = "healthyOnly";
|
||||
|
||||
private static final String SERVICE_NAME_PARAM = "serviceName";
|
||||
|
||||
private final String namespaceId;
|
||||
|
||||
private final ServerListManager serverListManager;
|
||||
@ -126,13 +154,13 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
params.put(CommonParams.SERVICE_NAME, groupedServiceName);
|
||||
params.put(CommonParams.GROUP_NAME, groupName);
|
||||
params.put(CommonParams.CLUSTER_NAME, instance.getClusterName());
|
||||
params.put("ip", instance.getIp());
|
||||
params.put("port", String.valueOf(instance.getPort()));
|
||||
params.put("weight", String.valueOf(instance.getWeight()));
|
||||
params.put(IP_PARAM, instance.getIp());
|
||||
params.put(PORT_PARAM, String.valueOf(instance.getPort()));
|
||||
params.put(WEIGHT_PARAM, String.valueOf(instance.getWeight()));
|
||||
params.put("enable", String.valueOf(instance.isEnabled()));
|
||||
params.put("healthy", String.valueOf(instance.isHealthy()));
|
||||
params.put("ephemeral", String.valueOf(instance.isEphemeral()));
|
||||
params.put("metadata", JacksonUtils.toJson(instance.getMetadata()));
|
||||
params.put(HEALTHY_PARAM, String.valueOf(instance.isHealthy()));
|
||||
params.put(EPHEMERAL_PARAM, String.valueOf(instance.isEphemeral()));
|
||||
params.put(META_PARAM, JacksonUtils.toJson(instance.getMetadata()));
|
||||
|
||||
reqApi(UtilAndComs.nacosUrlInstance, params, HttpMethod.POST);
|
||||
|
||||
@ -151,9 +179,9 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||
params.put(CommonParams.SERVICE_NAME, NamingUtils.getGroupedName(serviceName, groupName));
|
||||
params.put(CommonParams.CLUSTER_NAME, instance.getClusterName());
|
||||
params.put("ip", instance.getIp());
|
||||
params.put("port", String.valueOf(instance.getPort()));
|
||||
params.put("ephemeral", String.valueOf(instance.isEphemeral()));
|
||||
params.put(IP_PARAM, instance.getIp());
|
||||
params.put(PORT_PARAM, String.valueOf(instance.getPort()));
|
||||
params.put(EPHEMERAL_PARAM, String.valueOf(instance.isEphemeral()));
|
||||
|
||||
reqApi(UtilAndComs.nacosUrlInstance, params, HttpMethod.DELETE);
|
||||
}
|
||||
@ -168,12 +196,12 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
params.put(CommonParams.SERVICE_NAME, serviceName);
|
||||
params.put(CommonParams.GROUP_NAME, groupName);
|
||||
params.put(CommonParams.CLUSTER_NAME, instance.getClusterName());
|
||||
params.put("ip", instance.getIp());
|
||||
params.put("port", String.valueOf(instance.getPort()));
|
||||
params.put("weight", String.valueOf(instance.getWeight()));
|
||||
params.put("enabled", String.valueOf(instance.isEnabled()));
|
||||
params.put("ephemeral", String.valueOf(instance.isEphemeral()));
|
||||
params.put("metadata", JacksonUtils.toJson(instance.getMetadata()));
|
||||
params.put(IP_PARAM, instance.getIp());
|
||||
params.put(PORT_PARAM, String.valueOf(instance.getPort()));
|
||||
params.put(WEIGHT_PARAM, String.valueOf(instance.getWeight()));
|
||||
params.put(ENABLE_PARAM, String.valueOf(instance.isEnabled()));
|
||||
params.put(EPHEMERAL_PARAM, String.valueOf(instance.isEphemeral()));
|
||||
params.put(META_PARAM, JacksonUtils.toJson(instance.getMetadata()));
|
||||
|
||||
reqApi(UtilAndComs.nacosUrlInstance, params, HttpMethod.PUT);
|
||||
}
|
||||
@ -184,10 +212,10 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
final Map<String, String> params = new HashMap<String, String>(8);
|
||||
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||
params.put(CommonParams.SERVICE_NAME, NamingUtils.getGroupedName(serviceName, groupName));
|
||||
params.put("clusters", clusters);
|
||||
params.put("udpPort", String.valueOf(udpPort));
|
||||
params.put("clientIP", NetUtils.localIP());
|
||||
params.put("healthyOnly", String.valueOf(healthyOnly));
|
||||
params.put(CLUSTERS_PARAM, clusters);
|
||||
params.put(UDP_PORT_PARAM, String.valueOf(udpPort));
|
||||
params.put(CLIENT_IP_PARAM, NetUtils.localIP());
|
||||
params.put(HEALTHY_ONLY_PARAM, String.valueOf(healthyOnly));
|
||||
String result = reqApi(UtilAndComs.nacosUrlBase + "/instance/list", params, HttpMethod.GET);
|
||||
if (StringUtils.isNotEmpty(result)) {
|
||||
return JacksonUtils.toObj(result, ServiceInfo.class);
|
||||
@ -217,9 +245,9 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||
params.put(CommonParams.SERVICE_NAME, service.getName());
|
||||
params.put(CommonParams.GROUP_NAME, service.getGroupName());
|
||||
params.put("protectThreshold", String.valueOf(service.getProtectThreshold()));
|
||||
params.put("metadata", JacksonUtils.toJson(service.getMetadata()));
|
||||
params.put("selector", JacksonUtils.toJson(selector));
|
||||
params.put(PROTECT_THRESHOLD_PARAM, String.valueOf(service.getProtectThreshold()));
|
||||
params.put(META_PARAM, JacksonUtils.toJson(service.getMetadata()));
|
||||
params.put(SELECTOR_PARAM, JacksonUtils.toJson(selector));
|
||||
|
||||
reqApi(UtilAndComs.nacosUrlService, params, HttpMethod.POST);
|
||||
|
||||
@ -247,9 +275,9 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||
params.put(CommonParams.SERVICE_NAME, service.getName());
|
||||
params.put(CommonParams.GROUP_NAME, service.getGroupName());
|
||||
params.put("protectThreshold", String.valueOf(service.getProtectThreshold()));
|
||||
params.put("metadata", JacksonUtils.toJson(service.getMetadata()));
|
||||
params.put("selector", JacksonUtils.toJson(selector));
|
||||
params.put(PROTECT_THRESHOLD_PARAM, String.valueOf(service.getProtectThreshold()));
|
||||
params.put(META_PARAM, JacksonUtils.toJson(service.getMetadata()));
|
||||
params.put(SELECTOR_PARAM, JacksonUtils.toJson(selector));
|
||||
|
||||
reqApi(UtilAndComs.nacosUrlService, params, HttpMethod.PUT);
|
||||
}
|
||||
@ -275,8 +303,8 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
params.put(CommonParams.NAMESPACE_ID, namespaceId);
|
||||
params.put(CommonParams.SERVICE_NAME, beatInfo.getServiceName());
|
||||
params.put(CommonParams.CLUSTER_NAME, beatInfo.getCluster());
|
||||
params.put("ip", beatInfo.getIp());
|
||||
params.put("port", String.valueOf(beatInfo.getPort()));
|
||||
params.put(IP_PARAM, beatInfo.getIp());
|
||||
params.put(PORT_PARAM, String.valueOf(beatInfo.getPort()));
|
||||
String result = reqApi(UtilAndComs.nacosUrlBase + "/instance/beat", params, bodyMap, HttpMethod.PUT);
|
||||
return JacksonUtils.toObj(result);
|
||||
}
|
||||
@ -311,7 +339,7 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
break;
|
||||
case label:
|
||||
ExpressionSelector expressionSelector = (ExpressionSelector) selector;
|
||||
params.put("selector", JacksonUtils.toJson(expressionSelector));
|
||||
params.put(SELECTOR_PARAM, JacksonUtils.toJson(expressionSelector));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -434,7 +462,7 @@ public class NamingHttpClientProxy extends AbstractNamingClientProxy {
|
||||
long start = System.currentTimeMillis();
|
||||
long end = 0;
|
||||
params.putAll(getSecurityHeaders());
|
||||
params.putAll(getSpasHeaders(params.get("serviceName")));
|
||||
params.putAll(getSpasHeaders(params.get(SERVICE_NAME_PARAM)));
|
||||
Header header = NamingHttpUtil.builderHeader();
|
||||
|
||||
String url;
|
||||
|
@ -63,7 +63,7 @@ public class Chooser<K, T> {
|
||||
return ref.items.get(index);
|
||||
}
|
||||
|
||||
if (index >= 0 && index < ref.weights.length) {
|
||||
if (index < ref.weights.length) {
|
||||
if (random < ref.weights[index]) {
|
||||
return ref.items.get(index);
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ import java.util.concurrent.Callable;
|
||||
*/
|
||||
public class InitUtils {
|
||||
|
||||
private static final String DEFAULT_END_POINT_PORT = "8080";
|
||||
|
||||
/**
|
||||
* Add a difference to the name naming. This method simply initializes the namespace for Naming. Config
|
||||
* initialization is not the same, so it cannot be reused directly.
|
||||
@ -86,7 +88,7 @@ public class InitUtils {
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isEmpty(tmpNamespace) && properties != null) {
|
||||
if (StringUtils.isEmpty(tmpNamespace)) {
|
||||
tmpNamespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
|
||||
}
|
||||
|
||||
@ -180,7 +182,7 @@ public class InitUtils {
|
||||
endpointPort = TemplateUtils.stringEmptyAndThenExecute(endpointPort, new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return "8080";
|
||||
return DEFAULT_END_POINT_PORT;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -21,6 +21,7 @@ import com.alibaba.nacos.common.codec.Base64;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Sign util.
|
||||
@ -30,7 +31,7 @@ import java.nio.charset.Charset;
|
||||
*/
|
||||
public class SignUtil {
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
private static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
|
||||
public SignUtil() {
|
||||
}
|
||||
|
@ -64,4 +64,10 @@ public class UtilAndComs {
|
||||
|
||||
public static final String HTTPS = "https://";
|
||||
|
||||
public static final String ENV_CONFIGS = "00-00---000-ENV_CONFIGS-000---00-00";
|
||||
|
||||
public static final String VIP_CLIENT_FILE = "vipclient.properties";
|
||||
|
||||
public static final String ALL_HOSTS = "00-00---000-ALL_HOSTS-000---00-00";
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user