Skip to content

Commit

Permalink
Merge pull request #2557 from alibaba/develop
Browse files Browse the repository at this point in the history
1.2.1 merge to master
  • Loading branch information
nkorange authored Mar 31, 2020
2 parents 4200809 + fd523b5 commit fe923ab
Show file tree
Hide file tree
Showing 53 changed files with 701 additions and 1,005 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Contributors are welcomed to join Nacos project. Please check [CONTRIBUTING](./C
* [email protected]: Nacos usage general discussion.
* [email protected]: Nacos developer discussion (APIs, feature design, etc).
* [email protected]: Commits notice, very high frequency.
* Join us from DingDing.
* Join us from DingDing(Group 1: 21708933(full), Group 2: 30438813).

![cwex](https://img.alicdn.com/tfs/TB1bpBlQmrqK1RjSZK9XXXyypXa-830-972.png_288x480q80.jpg)
![Nacos](https://img.alicdn.com/tfs/TB1TBKEzpP7gK0jSZFjXXc5aXXa-199-220.png)

## Download

Expand Down
2 changes: 1 addition & 1 deletion address/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,14 @@ public UpdateTask(String serviceName, String clusters) {

@Override
public void run() {
long delayTime = -1;

try {
ServiceInfo serviceObj = serviceInfoMap.get(ServiceInfo.getKey(serviceName, clusters));

if (serviceObj == null) {
updateServiceNow(serviceName, clusters);
executor.schedule(this, DEFAULT_DELAY, TimeUnit.MILLISECONDS);
delayTime = DEFAULT_DELAY;
return;
}

Expand All @@ -341,11 +343,15 @@ public void run() {
return;
}

executor.schedule(this, serviceObj.getCacheMillis(), TimeUnit.MILLISECONDS);
delayTime = serviceObj.getCacheMillis();


} catch (Throwable e) {
NAMING_LOGGER.warn("[NA] failed to update serviceName: " + serviceName, e);
} finally {
if (delayTime > 0) {
executor.schedule(this, delayTime, TimeUnit.MILLISECONDS);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@

import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.*;

Expand Down Expand Up @@ -327,7 +329,11 @@ public JSONObject sendBeat(BeatInfo beatInfo, boolean lightBeatEnabled) throws N
Map<String, String> params = new HashMap<String, String>(8);
String body = StringUtils.EMPTY;
if (!lightBeatEnabled) {
body = "beat=" + JSON.toJSONString(beatInfo);
try {
body = "beat=" + URLEncoder.encode(JSON.toJSONString(beatInfo), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new NacosException(NacosException.SERVER_ERROR, "encode beatInfo error", e);
}
}
params.put(CommonParams.NAMESPACE_ID, namespaceId);
params.put(CommonParams.SERVICE_NAME, beatInfo.getServiceName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.client.config.impl.HttpSimpleClient;
import org.slf4j.Logger;
import org.apache.commons.lang3.StringUtils;

import java.io.InputStream;
import java.util.Properties;
Expand Down Expand Up @@ -174,12 +175,12 @@ public String call() {
@Override
public String call() {
String namespace = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE);
return org.apache.commons.lang3.StringUtils.isNotBlank(namespace) ? namespace : StringUtils.EMPTY;
return StringUtils.isNotBlank(namespace) ? namespace : StringUtils.EMPTY;
}
});
}

if (org.apache.commons.lang3.StringUtils.isBlank(namespaceTmp)) {
if (StringUtils.isBlank(namespaceTmp)) {
namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
}
return StringUtils.isNotBlank(namespaceTmp) ? namespaceTmp.trim() : StringUtils.EMPTY;
Expand Down
2 changes: 1 addition & 1 deletion cmdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
47 changes: 24 additions & 23 deletions common/src/main/java/com/alibaba/nacos/common/utils/Md5Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.alibaba.nacos.common.utils;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
* MD5 generator
Expand All @@ -24,35 +26,34 @@
*/
public class Md5Utils {

private static ThreadLocal<MessageDigest> MESSAGE_DIGEST_LOCAL = new ThreadLocal<MessageDigest>() {
@Override
protected MessageDigest initialValue() {
try {
return MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
return null;
}
}
};

private static final int HEX_VALUE_COUNT = 16;

public static String getMD5(byte[] bytes) {
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
char[] str = new char[16 * 2];
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
md.update(bytes);
byte[] tmp = md.digest();
int k = 0;
for (int i = 0; i < HEX_VALUE_COUNT; i++) {
byte byte0 = tmp[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
} catch (Exception e) {
e.printStackTrace();
public static String getMD5(byte[] bytes) throws NoSuchAlgorithmException {

MessageDigest messageDigest = MESSAGE_DIGEST_LOCAL.get();
if (messageDigest != null) {
return new BigInteger(1, messageDigest.digest(bytes)).toString(HEX_VALUE_COUNT);
}
return new String(str);

throw new NoSuchAlgorithmException("MessageDigest get MD5 instance error");
}

public static String getMD5(String value, String encode) {
String result = "";
try {
result = getMD5(value.getBytes(encode));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return getMD5(value.getBytes(encode));
} catch (Exception e) {
throw new RuntimeException(e);
}

return result;
}
}
2 changes: 1 addition & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package com.alibaba.nacos.config.server.aspect;

import com.alibaba.nacos.common.utils.Md5Utils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
import com.alibaba.nacos.config.server.service.ConfigService;
import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.MD5;
import com.alibaba.nacos.config.server.utils.RequestUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
Expand Down Expand Up @@ -66,7 +67,7 @@ public class RequestLogAspect {
public Object interfacePublishSingle(ProceedingJoinPoint pjp, HttpServletRequest request,
HttpServletResponse response, String dataId, String group, String tenant,
String content) throws Throwable {
final String md5 = content == null ? null : MD5.getInstance().getMD5String(content);
final String md5 = content == null ? null : Md5Utils.getMD5(content, Constants.ENCODE);
MetricsMonitor.getPublishMonitor().incrementAndGet();
return logClientRequest("publish", pjp, request, response, dataId, group, tenant, md5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,
String tenant,
@RequestParam(value = "tag", required = false) String tag)
throws IOException, ServletException, NacosException {
tenant = processTenant(tenant);
// check params
ParamUtils.checkParam(dataId, group, "datumId", "content");
ParamUtils.checkParam(tag);
Expand Down Expand Up @@ -432,6 +433,7 @@ public ResponseEntity<byte[]> exportConfig(@RequestParam(value = "dataId", requi
defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "ids", required = false) List<Long> ids) {
ids.removeAll(Collections.singleton(null));
tenant = processTenant(tenant);
List<ConfigAllInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>();
StringBuilder metaData = null;
Expand Down Expand Up @@ -620,4 +622,11 @@ public RestResult<Map<String, Object>> cloneConfig(HttpServletRequest request,
return ResultBuilder.buildSuccessResult("克隆成功", saveResult);
}

private String processTenant(String tenant){
if (StringUtils.isEmpty(tenant) || NAMESPACE_PUBLIC_KEY.equalsIgnoreCase(tenant)) {
return "";
}
return tenant;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
package com.alibaba.nacos.config.server.model;

import com.alibaba.nacos.config.server.utils.MD5;
import com.alibaba.nacos.common.utils.Md5Utils;
import com.alibaba.nacos.config.server.constant.Constants;

import java.io.PrintWriter;
import java.io.Serializable;
Expand Down Expand Up @@ -46,7 +47,7 @@ public ConfigInfoBase(String dataId, String group, String content) {
this.group = group;
this.content = content;
if (this.content != null) {
this.md5 = MD5.getInstance().getMD5String(this.content);
this.md5 = Md5Utils.getMD5(this.content, Constants.ENCODE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package com.alibaba.nacos.config.server.service;

import com.alibaba.nacos.common.utils.Md5Utils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.CacheItem;
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
import com.alibaba.nacos.config.server.utils.GroupKey;
import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.MD5;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -70,7 +70,8 @@ static public boolean dump(String dataId, String group, String tenant, String co
}

try {
final String md5 = MD5.getInstance().getMD5String(content);
final String md5 = Md5Utils.getMD5(content, Constants.ENCODE);

if (md5.equals(ConfigService.getContentMd5(groupKey))) {
dumpLog.warn(
"[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
Expand Down Expand Up @@ -115,7 +116,7 @@ static public boolean dumpBeta(String dataId, String group, String tenant, Strin
}

try {
final String md5 = MD5.getInstance().getMD5String(content);
final String md5 = Md5Utils.getMD5(content, Constants.ENCODE);
if (md5.equals(ConfigService.getContentBetaMd5(groupKey))) {
dumpLog.warn(
"[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
Expand Down Expand Up @@ -154,7 +155,7 @@ static public boolean dumpTag(String dataId, String group, String tenant, String
}

try {
final String md5 = MD5.getInstance().getMD5String(content);
final String md5 = Md5Utils.getMD5(content, Constants.ENCODE);
if (md5.equals(ConfigService.getContentTagMd5(groupKey, tag))) {
dumpLog.warn(
"[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
Expand Down Expand Up @@ -191,7 +192,7 @@ static public boolean dumpChange(String dataId, String group, String tenant, Str
}

try {
final String md5 = MD5.getInstance().getMD5String(content);
final String md5 = Md5Utils.getMD5(content, Constants.ENCODE);
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
if (md5.equals(loacalMd5)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package com.alibaba.nacos.config.server.service;

import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.Md5Utils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.MD5;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -172,7 +172,7 @@ static public String getConfig(String dataId, String group, String tenant)

static public String getLocalConfigMd5(String dataId, String group, String tenant)
throws IOException {
return MD5.getInstance().getMD5String(getConfig(dataId, group, tenant));
return Md5Utils.getMD5(getConfig(dataId, group, tenant), Constants.ENCODE);
}

static public File heartBeatFile() {
Expand Down
Loading

0 comments on commit fe923ab

Please sign in to comment.