Search in sources :

Example 21 with Instance

use of com.alibaba.nacos.naming.core.Instance in project nacos by alibaba.

the class MysqlHealthCheckProcessor method process.

@Override
public void process(HealthCheckTask task) {
    List<Instance> ips = task.getCluster().allIPs(false);
    SRV_LOG.debug("mysql check, ips:" + ips);
    if (CollectionUtils.isEmpty(ips)) {
        return;
    }
    for (Instance ip : ips) {
        try {
            if (ip.isMarked()) {
                if (SRV_LOG.isDebugEnabled()) {
                    SRV_LOG.debug("mysql check, ip is marked as to skip health check, ip: {}", ip.getIp());
                }
                continue;
            }
            if (!ip.markChecking()) {
                SRV_LOG.warn("mysql check started before last one finished, service: {}:{}:{}", task.getCluster().getService().getName(), task.getCluster().getName(), ip.getIp());
                healthCheckCommon.reEvaluateCheckRT(task.getCheckRtNormalized() * 2, task, switchDomain.getMysqlHealthParams());
                continue;
            }
            GlobalExecutor.executeMysqlCheckTask(new MysqlCheckTask(ip, task));
            MetricsMonitor.getMysqlHealthCheckMonitor().incrementAndGet();
        } catch (Exception e) {
            ip.setCheckRt(switchDomain.getMysqlHealthParams().getMax());
            healthCheckCommon.checkFail(ip, task, "mysql:error:" + e.getMessage());
            healthCheckCommon.reEvaluateCheckRT(switchDomain.getMysqlHealthParams().getMax(), task, switchDomain.getMysqlHealthParams());
        }
    }
}
Also used : Instance(com.alibaba.nacos.naming.core.Instance) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 22 with Instance

use of com.alibaba.nacos.naming.core.Instance in project nacos by alibaba.

the class DefaultInstanceUpgradeHelper method toV1.

@Override
public Instance toV1(com.alibaba.nacos.api.naming.pojo.Instance v2) {
    Instance v1 = new Instance(v2.getIp(), v2.getPort(), v2.getClusterName());
    BeanUtils.copyProperties(v2, v1);
    return v1;
}
Also used : Instance(com.alibaba.nacos.naming.core.Instance)

Example 23 with Instance

use of com.alibaba.nacos.naming.core.Instance in project nacos by alibaba.

the class TcpSuperSenseProcessor method process.

@Override
public void process(HealthCheckTask task) {
    List<Instance> ips = task.getCluster().allIPs(false);
    if (CollectionUtils.isEmpty(ips)) {
        return;
    }
    for (Instance ip : ips) {
        if (ip.isMarked()) {
            if (SRV_LOG.isDebugEnabled()) {
                SRV_LOG.debug("tcp check, ip is marked as to skip health check, ip:" + ip.getIp());
            }
            continue;
        }
        if (!ip.markChecking()) {
            SRV_LOG.warn("tcp check started before last one finished, service: " + task.getCluster().getService().getName() + ":" + task.getCluster().getName() + ":" + ip.getIp() + ":" + ip.getPort());
            healthCheckCommon.reEvaluateCheckRT(task.getCheckRtNormalized() * 2, task, switchDomain.getTcpHealthParams());
            continue;
        }
        Beat beat = new Beat(ip, task);
        taskQueue.add(beat);
        MetricsMonitor.getTcpHealthCheckMonitor().incrementAndGet();
    }
}
Also used : Instance(com.alibaba.nacos.naming.core.Instance)

Example 24 with Instance

use of com.alibaba.nacos.naming.core.Instance in project nacos by alibaba.

the class RaftStoreTest method wrietDatum.

@Test
public void wrietDatum() throws Exception {
    Datum<Instances> datum = new Datum<>();
    String key = KeyBuilder.buildInstanceListKey(TEST_NAMESPACE, TEST_SERVICE_NAME, false);
    datum.key = key;
    datum.timestamp.getAndIncrement();
    datum.value = new Instances();
    Instance instance = new Instance("1.1.1.1", 1, TEST_CLUSTER_NAME);
    datum.value.getInstanceList().add(instance);
    instance = new Instance("2.2.2.2", 2, TEST_CLUSTER_NAME);
    datum.value.getInstanceList().add(instance);
    raftStore.write(datum);
    raftCore.init();
    Datum result = raftCore.getDatum(key);
    Assert.assertEquals(key, result.key);
    Assert.assertEquals(1, result.timestamp.intValue());
    Assert.assertEquals(datum.value.toString(), result.value.toString());
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) Datum(com.alibaba.nacos.naming.consistency.Datum) Instance(com.alibaba.nacos.naming.core.Instance) Test(org.junit.Test) BaseTest(com.alibaba.nacos.naming.BaseTest)

Example 25 with Instance

use of com.alibaba.nacos.naming.core.Instance in project nacos by alibaba.

the class ClientBeatCheckTaskTest method testIpDeleteNotTimeOut.

@Test
public void testIpDeleteNotTimeOut() {
    Instance instance = new Instance();
    instance.setLastBeat(System.currentTimeMillis());
    instance.setMarked(true);
    instance.setHealthy(true);
    Map<String, String> metadata = new HashMap<>();
    metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, "10000");
    instance.setMetadata(metadata);
    Mockito.doReturn(true).when(distroMapperSpy).responsible(null);
    clientBeatCheckTask.run();
}
Also used : Instance(com.alibaba.nacos.naming.core.Instance) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Instance (com.alibaba.nacos.naming.core.Instance)26 Test (org.junit.Test)13 Instances (com.alibaba.nacos.naming.core.Instances)6 HashMap (java.util.HashMap)6 BaseTest (com.alibaba.nacos.naming.BaseTest)5 Cluster (com.alibaba.nacos.naming.core.Cluster)5 Service (com.alibaba.nacos.naming.core.Service)5 ArrayList (java.util.ArrayList)5 Datum (com.alibaba.nacos.naming.consistency.Datum)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 LinkedList (java.util.LinkedList)3 InstanceOperationInfo (com.alibaba.nacos.naming.pojo.InstanceOperationInfo)2 Function (java.util.function.Function)2 Before (org.junit.Before)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)1 AbstractHealthChecker (com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker)1 Http (com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http)1