use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class ClientBeatProcessor method run.
@Override
public void run() {
Service service = this.service;
if (Loggers.EVT_LOG.isDebugEnabled()) {
Loggers.EVT_LOG.debug("[CLIENT-BEAT] processing beat: {}", rsInfo.toString());
}
String ip = rsInfo.getIp();
String clusterName = rsInfo.getCluster();
int port = rsInfo.getPort();
Cluster cluster = service.getClusterMap().get(clusterName);
List<Instance> instances = cluster.allIPs(true);
for (Instance instance : instances) {
if (instance.getIp().equals(ip) && instance.getPort() == port) {
if (Loggers.EVT_LOG.isDebugEnabled()) {
Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: {}", rsInfo.toString());
}
instance.setLastBeat(System.currentTimeMillis());
if (!instance.isMarked() && !instance.isHealthy()) {
instance.setHealthy(true);
Loggers.EVT_LOG.info("service: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: client beat ok", cluster.getService().getName(), ip, port, cluster.getName(), UtilsAndCommons.LOCALHOST_SITE);
getPushService().serviceChanged(service);
}
}
}
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class HealthCheckCommon method checkFail.
/**
* Health check fail, when instance check failed count more than max failed time, set unhealthy.
*
* @param ip instance
* @param task health check task
* @param msg message
*/
public void checkFail(Instance ip, HealthCheckTask task, String msg) {
Cluster cluster = task.getCluster();
try {
if (ip.isHealthy() || ip.isMockValid()) {
if (ip.getFailCount().incrementAndGet() >= switchDomain.getCheckTimes()) {
if (distroMapper.responsible(cluster, ip)) {
ip.setHealthy(false);
ip.setMockValid(false);
Service service = cluster.getService();
service.setLastModifiedMillis(System.currentTimeMillis());
pushService.serviceChanged(service);
Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
} else {
Loggers.EVT_LOG.info("serviceName: {} {PROBE} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
}
} else {
Loggers.EVT_LOG.info("serviceName: {} {OTHER} {IP-DISABLED} pre-invalid: {}:{}@{} in {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), ip.getFailCount(), msg);
}
}
} catch (Throwable t) {
Loggers.SRV_LOG.error("[CHECK-FAIL] error when close check task.", t);
}
ip.getOkCount().set(0);
ip.setBeingChecked(false);
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class HealthCheckCommon method checkFailNow.
/**
* Health check fail, set instance unhealthy directly.
*
* @param ip instance
* @param task health check task
* @param msg message
*/
public void checkFailNow(Instance ip, HealthCheckTask task, String msg) {
Cluster cluster = task.getCluster();
try {
if (ip.isHealthy() || ip.isMockValid()) {
if (distroMapper.responsible(cluster, ip)) {
ip.setHealthy(false);
ip.setMockValid(false);
Service service = cluster.getService();
service.setLastModifiedMillis(System.currentTimeMillis());
pushService.serviceChanged(service);
Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-DISABLED} invalid-now: {}:{}@{}, region: {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
} else {
if (ip.isMockValid()) {
ip.setMockValid(false);
Loggers.EVT_LOG.info("serviceName: {} {PROBE} {IP-DISABLED} invalid-now: {}:{}@{}, region: {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg);
}
}
}
} catch (Throwable t) {
Loggers.SRV_LOG.error("[CHECK-FAIL-NOW] error when close check task.", t);
}
ip.getOkCount().set(0);
ip.setBeingChecked(false);
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class AsyncServicesCheckTask method run.
@Override
public void run() {
if (upgradeJudgement.isUseGrpcFeatures()) {
return;
}
try {
ServiceManager serviceManager = ApplicationUtils.getBean(ServiceManager.class);
ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
Map<String, Service> v1Services = new HashMap<>(INITIALCAPACITY);
for (String each : serviceManager.getAllNamespaces()) {
for (Map.Entry<String, Service> entry : serviceManager.chooseServiceMap(each).entrySet()) {
v1Services.put(buildServiceKey(each, entry.getKey()), entry.getValue());
checkService(each, entry.getKey(), entry.getValue(), serviceStorage);
}
}
Map<String, com.alibaba.nacos.naming.core.v2.pojo.Service> v2Services = new HashMap<>(INITIALCAPACITY);
for (String each : com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getAllNamespaces()) {
for (com.alibaba.nacos.naming.core.v2.pojo.Service serviceV2 : com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getSingletons(each)) {
v2Services.put(buildServiceKey(each, serviceV2.getGroupedServiceName()), serviceV2);
}
}
// only check v2 services when upgrading.
v2Services.keySet().removeIf(v1Services::containsKey);
if (v2Services.isEmpty()) {
return;
}
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("{} service in v2 to removed.", v2Services.size());
}
for (com.alibaba.nacos.naming.core.v2.pojo.Service service : v2Services.values()) {
deleteV2Service(service);
}
} catch (Exception e) {
Loggers.SRV_LOG.warn("async check for service error", e);
}
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class ServiceChangeEventTest method testGetService.
@Test
public void testGetService() {
ServiceChangeEvent serviceChangeEvent = new ServiceChangeEvent(object, service);
Service service = serviceChangeEvent.getService();
Assert.assertNotNull(service);
Assert.assertEquals(service, service);
}
Aggregations