Merge pull request #1630 from alibaba/feature_enhance_interface

upgrade fastjson version and Optimizing Some interfaces
This commit is contained in:
Fury Zhu 2019-08-01 11:00:55 +08:00 committed by GitHub
commit 0a08be2b96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 12 deletions

View File

@ -147,11 +147,7 @@ public class ServiceManager implements RecordListener<Service> {
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), oldDom);
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), oldDom);
} else {
putService(service);
service.init();
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), service);
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), service);
Loggers.SRV_LOG.info("[NEW-SERVICE] {}", service.toJSON());
putServiceAndInit(service);
}
} catch (Throwable e) {
Loggers.SRV_LOG.error("[NACOS-SERVICE] error while processing service update", e);
@ -412,16 +408,37 @@ public class ServiceManager implements RecordListener<Service> {
}
service.validate();
if (local) {
putService(service);
service.init();
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), service);
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), service);
putServiceAndInit(service);
} else {
addOrReplaceService(service);
}
}
}
public void putServiceIfAbsent(Service service, boolean local, Cluster cluster) throws NacosException {
final String namespaceId = service.getNamespaceId();
final String serviceName = service.getName();
if (getService(namespaceId, serviceName) != null) {
return;
}
Loggers.SRV_LOG.info("creating empty service {}:{}", namespaceId, serviceName);
// now validate the service. if failed, exception will be thrown
service.setLastModifiedMillis(System.currentTimeMillis());
service.recalculateChecksum();
if (cluster != null) {
cluster.setService(service);
service.getClusterMap().put(cluster.getName(), cluster);
}
service.validate();
if (local) {
putServiceAndInit(service);
} else {
addOrReplaceService(service);
}
}
/**
* Register an instance to a service in AP mode.
* <p>
@ -477,11 +494,14 @@ public class ServiceManager implements RecordListener<Service> {
}
public void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Instance... ips) throws NacosException {
Service service = getService(namespaceId, serviceName);
removeInstance(namespaceId, serviceName, ephemeral, service, ips);
}
public void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Service service, Instance... ips) throws NacosException {
String key = KeyBuilder.buildInstanceListKey(namespaceId, serviceName, ephemeral);
Service service = getService(namespaceId, serviceName);
List<Instance> instanceList = substractIpAddresses(service, ephemeral, ips);
Instances instances = new Instances();
@ -601,6 +621,14 @@ public class ServiceManager implements RecordListener<Service> {
serviceMap.get(service.getNamespaceId()).put(service.getName(), service);
}
private void putServiceAndInit(Service service) throws NacosException {
putService(service);
service.init();
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), service);
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), service);
Loggers.SRV_LOG.info("[NEW-SERVICE] {}", service.toJSON());
}
public List<Service> searchServices(String namespaceId, String regex) {
List<Service> result = new ArrayList<>();
for (Map.Entry<String, Service> entry : chooseServiceMap(namespaceId).entrySet()) {

View File

@ -22,6 +22,7 @@ import com.alibaba.nacos.naming.boot.SpringContext;
import com.alibaba.nacos.naming.core.DistroMapper;
import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.healthcheck.events.InstanceHeartbeatTimeoutEvent;
import com.alibaba.nacos.naming.misc.*;
import com.alibaba.nacos.naming.push.PushService;
import com.ning.http.client.AsyncCompletionHandler;
@ -82,6 +83,7 @@ public class ClientBeatCheckTask implements Runnable {
instance.getIp(), instance.getPort(), instance.getClusterName(), service.getName(),
UtilsAndCommons.LOCALHOST_SITE, instance.getInstanceHeartBeatTimeOut(), instance.getLastBeat());
getPushService().serviceChanged(service);
SpringContext.getAppContext().publishEvent(new InstanceHeartbeatTimeoutEvent(this, instance));
}
}
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2019 the original author or authors.
*
* 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.healthcheck.events;
import com.alibaba.nacos.naming.core.Instance;
import org.springframework.context.ApplicationEvent;
/**
* @author pbting
* @date 2019-05-28 8:29 PM
*/
public class InstanceHeartbeatTimeoutEvent extends ApplicationEvent {
private Instance instance;
public InstanceHeartbeatTimeoutEvent(Object source, Instance instance) {
super(source);
this.instance = instance;
}
public void setInstance(Instance instance) {
this.instance = instance;
}
public Instance getInstance() {
return instance;
}
}

View File

@ -523,7 +523,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
<version>1.2.58</version>
</dependency>
<!-- javax libs-->