Skip to content

Commit

Permalink
Merge pull request #6 from alibaba/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pbting authored Apr 11, 2019
2 parents b71faa8 + 5037467 commit 31b91e6
Show file tree
Hide file tree
Showing 35 changed files with 163 additions and 44 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 wechat. Welcome words: Nacos.
* Join us from DingDing.

![cwex](http://acm-public.oss-cn-hangzhou.aliyuncs.com/xuc.png)
![cwex](https://img.alicdn.com/tfs/TB1bpBlQmrqK1RjSZK9XXXyypXa-830-972.png_288x480q80.jpg)


## Who is using
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.0.0-RC4</version>
<version>1.0.0</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.0.0-RC4</version>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class NacosConfigService implements ConfigService {
private static final Logger LOGGER = LogUtils.logger(NacosConfigService.class);

private final long POST_TIMEOUT = 3000L;

private static final String EMPTY = "";

/**
* http agent
*/
Expand Down Expand Up @@ -95,14 +98,14 @@ public String call() {
@Override
public String call() {
String namespace = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_NAMESPACE);
return StringUtils.isNotBlank(namespace) ? namespace : "";
return StringUtils.isNotBlank(namespace) ? namespace : EMPTY;
}
});

if (StringUtils.isBlank(namespaceTmp)) {
namespaceTmp = properties.getProperty(PropertyKeyConst.NAMESPACE);
}
namespace = namespaceTmp;
namespace = StringUtils.isNotBlank(namespaceTmp) ? namespaceTmp.trim() : EMPTY;
properties.put(PropertyKeyConst.NAMESPACE, namespace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class TenantUtil {

static String userTenant = "";
private static String userTenant = "";

static {
userTenant = System.getProperty("tenant.id", "");
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.0.0-RC4</version>
<version>1.0.0</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.0.0-RC4</version>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
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.0.0-RC4</version>
<version>1.0.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion console/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.0.0-RC4</version>
<version>1.0.0</version>
</parent>
<artifactId>nacos-console</artifactId>
<!--<packaging>war</packaging>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=

nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
Expand Down
2 changes: 1 addition & 1 deletion core/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.0.0-RC4</version>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
1 change: 0 additions & 1 deletion distribution/bin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ else
JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
fi

JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"
JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}"
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/nacos-server.jar"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
Expand Down
2 changes: 1 addition & 1 deletion distribution/conf/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ server.tomcat.basedir=

nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**

nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
Expand Down
2 changes: 1 addition & 1 deletion distribution/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.0.0-RC4</version>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/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.0.0-RC4</version>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion naming/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.0.0-RC4</version>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public void onRemove(String key) {
return;
}

listeners.remove(key);

notifier.addTask(key, ApplyAction.DELETE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public class TaskDispatcher {

@PostConstruct
public void init() {

if (partitionConfig.getTaskDispatchThreadCount() > Runtime.getRuntime().availableProcessors()) {
Loggers.EPHEMERAL.error("should not larger than {}, current is: {}",
Runtime.getRuntime().availableProcessors(), partitionConfig.getTaskDispatchThreadCount());
throw new RuntimeException("task dispatch thread count is too large!");
}

for (int i = 0; i < partitionConfig.getTaskDispatchThreadCount(); i++) {
TaskScheduler taskScheduler = new TaskScheduler(i);
taskSchedulerList.add(taskScheduler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ public void remove(String key) throws NacosException {
Datum datum = new Datum();
datum.key = key;
raftCore.onDelete(datum.key, peers.getLeader());
raftCore.unlistenAll(key);
return;
}
raftCore.signalDelete(key);
raftCore.unlistenAll(key);
} catch (Exception e) {
Loggers.RAFT.error("Raft remove failed.", e);
throw new NacosException(NacosException.SERVER_ERROR, "Raft remove failed, key:" + key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ public void unlisten(String key, RecordListener listener) {
}
}

public void unlistenAll(String key) {
listeners.remove(key);
}

public void setTerm(long term) {
peers.setTerm(term);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alibaba.nacos.naming.consistency.ApplyAction;
import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.consistency.KeyBuilder;
import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Instances;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.misc.Loggers;
Expand All @@ -37,6 +38,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -157,8 +159,34 @@ public synchronized Datum readDatum(File file, String namespaceId) throws IOExce
}

if (KeyBuilder.matchInstanceListKey(file.getName())) {
return JSON.parseObject(json, new TypeReference<Datum<Instances>>() {
});

Datum<Instances> instancesDatum;

try {
instancesDatum = JSON.parseObject(json, new TypeReference<Datum<Instances>>() {
});
} catch (Exception e) {
JSONObject jsonObject = JSON.parseObject(json);
instancesDatum = new Datum<>();
instancesDatum.timestamp.set(jsonObject.getLongValue("timestamp"));

String key = jsonObject.getString("key");
String serviceName = KeyBuilder.getServiceName(key);
key = key.substring(0, key.indexOf(serviceName)) +
Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName;

instancesDatum.key = key;
instancesDatum.value = new Instances();
instancesDatum.value.setInstanceList(JSON.parseObject(jsonObject.getString("value"),
new TypeReference<List<Instance>>(){}));
if (!instancesDatum.value.getInstanceList().isEmpty()) {
for (Instance instance : instancesDatum.value.getInstanceList()) {
instance.setEphemeral(false);
}
}
}

return instancesDatum;
}

return JSON.parseObject(json, Datum.class);
Expand Down Expand Up @@ -208,6 +236,21 @@ public synchronized void write(final Datum datum) throws Exception {
fc.close();
}
}

// remove old format file:
if (StringUtils.isNoneBlank(namespaceId)) {
if (datum.key.contains(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER)) {
String oldFormatKey =
datum.key.replace(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER, StringUtils.EMPTY);

cacheFile = new File(cacheDir + File.separator + namespaceId + File.separator + encodeFileName(oldFormatKey));
if (cacheFile.exists() && !cacheFile.delete()) {
Loggers.RAFT.error("[RAFT-DELETE] failed to delete old format datum: {}, value: {}",
datum.key, datum.value);
throw new IllegalStateException("failed to delete old format datum: " + datum.key);
}
}
}
}

private File[] listCaches() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public String update(HttpServletRequest request) throws Exception {
Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName);
cluster = new Cluster();
cluster.setName(clusterName);
cluster.setService(service);
}

cluster.setDefCkport(NumberUtils.toInt(checkPort));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public String deregister(HttpServletRequest request) throws Exception {

Service service = serviceManager.getService(namespaceId, serviceName);
if (service == null) {
Loggers.SRV_LOG.warn("remove instance from non-exist service: {}", serviceName);
return "ok";
}

Expand All @@ -120,6 +121,7 @@ public String deregister(HttpServletRequest request) throws Exception {
return "ok";
}

@CanDistro
@RequestMapping(value = "", method = RequestMethod.PUT)
public String update(HttpServletRequest request) throws Exception {
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Expand All @@ -133,10 +135,10 @@ public String update(HttpServletRequest request) throws Exception {
ClientInfo clientInfo = new ClientInfo(agent);

if (clientInfo.type == ClientInfo.ClientType.JAVA &&
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) < 0) {
serviceManager.registerInstance(namespaceId, serviceName, parseInstance(request));
} else {
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) >= 0) {
serviceManager.updateInstance(namespaceId, serviceName, parseInstance(request));
} else {
serviceManager.registerInstance(namespaceId, serviceName, parseInstance(request));
}
return "ok";
}
Expand Down Expand Up @@ -332,10 +334,12 @@ private Instance getIPAddress(HttpServletRequest request) {
String ip = WebUtils.required(request, "ip");
String port = WebUtils.required(request, "port");
String weight = WebUtils.optional(request, "weight", "1");
String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, UtilsAndCommons.DEFAULT_CLUSTER_NAME);
String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, StringUtils.EMPTY);
if (StringUtils.isBlank(cluster)) {
cluster = WebUtils.optional(request, "cluster", UtilsAndCommons.DEFAULT_CLUSTER_NAME);
}
boolean healthy = BooleanUtils.toBoolean(WebUtils.optional(request, "healthy", "true"));
boolean enabled = BooleanUtils.toBoolean(WebUtils.optional(request, "enable", "true"));
// If server running in CP mode, we set this flag to false:
boolean ephemeral = BooleanUtils.toBoolean(WebUtils.optional(request, "ephemeral",
String.valueOf(switchDomain.isDefaultInstanceEphemeral())));

Expand All @@ -360,6 +364,7 @@ public void checkIfDisabled(Service service) throws Exception {
public JSONObject doSrvIPXT(String namespaceId, String serviceName, String agent, String clusters, String clientIP, int udpPort,
String env, boolean isCheck, String app, String tid, boolean healthyOnly) throws Exception {

ClientInfo clientInfo = new ClientInfo(agent);
JSONObject result = new JSONObject();
Service service = serviceManager.getService(namespaceId, serviceName);

Expand Down Expand Up @@ -403,8 +408,14 @@ public JSONObject doSrvIPXT(String namespaceId, String serviceName, String agent
Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName);
}

if (clientInfo.type == ClientInfo.ClientType.JAVA &&
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) >= 0) {
result.put("dom", serviceName);
} else {
result.put("dom", NamingUtils.getServiceName(serviceName));
}

result.put("hosts", new JSONArray());
result.put("dom", serviceName);
result.put("name", serviceName);
result.put("cacheMillis", cacheMillis);
result.put("lastRefTime", System.currentTimeMillis());
Expand Down Expand Up @@ -450,8 +461,6 @@ public JSONObject doSrvIPXT(String namespaceId, String serviceName, String agent

JSONArray hosts = new JSONArray();

ClientInfo clientInfo = new ClientInfo(agent);

for (Map.Entry<Boolean, List<Instance>> entry : ipMap.entrySet()) {
List<Instance> ips = entry.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public Cluster() {

public Cluster(String clusterName) {
this.setName(clusterName);
validate();
}

public int getDefIPPort() {
Expand Down Expand Up @@ -99,7 +100,9 @@ public void init() {
}

public void destroy() {
checkTask.setCancelled(true);
if (checkTask != null) {
checkTask.setCancelled(true);
}
}

public HealthCheckTask getHealthCheckTask() {
Expand Down
Loading

0 comments on commit 31b91e6

Please sign in to comment.