Search in sources :

Example 6 with InstanceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata in project nacos by alibaba.

the class InstanceOperatorClientImpl method cloneMetadata.

private InstanceMetadata cloneMetadata(InstanceMetadata instanceMetadata) {
    InstanceMetadata result = new InstanceMetadata();
    result.setExtendData(new HashMap<>(instanceMetadata.getExtendData()));
    result.setWeight(instanceMetadata.getWeight());
    result.setEnabled(instanceMetadata.isEnabled());
    return result;
}
Also used : InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)

Example 7 with InstanceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata in project nacos by alibaba.

the class InstanceOperatorClientImpl method buildMetadata.

private InstanceMetadata buildMetadata(Instance instance) {
    InstanceMetadata result = new InstanceMetadata();
    result.setEnabled(instance.isEnabled());
    result.setWeight(instance.getWeight());
    result.getExtendData().putAll(instance.getMetadata());
    return result;
}
Also used : InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)

Example 8 with InstanceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata in project nacos by alibaba.

the class InstanceOperatorClientImpl method getHeartBeatInterval.

@Override
public long getHeartBeatInterval(String namespaceId, String serviceName, String ip, int port, String cluster) {
    Service service = getService(namespaceId, serviceName, true);
    String metadataId = InstancePublishInfo.genMetadataId(ip, port, cluster);
    Optional<InstanceMetadata> metadata = metadataManager.getInstanceMetadata(service, metadataId);
    if (metadata.isPresent() && metadata.get().getExtendData().containsKey(PreservedMetadataKeys.HEART_BEAT_INTERVAL)) {
        return ConvertUtils.toLong(metadata.get().getExtendData().get(PreservedMetadataKeys.HEART_BEAT_INTERVAL));
    }
    String clientId = IpPortBasedClient.getClientId(ip + InternetAddressUtil.IP_PORT_SPLITER + port, true);
    Client client = clientManager.getClient(clientId);
    InstancePublishInfo instance = null != client ? client.getInstancePublishInfo(service) : null;
    if (null != instance && instance.getExtendDatum().containsKey(PreservedMetadataKeys.HEART_BEAT_INTERVAL)) {
        return ConvertUtils.toLong(instance.getExtendDatum().get(PreservedMetadataKeys.HEART_BEAT_INTERVAL));
    }
    return switchDomain.getClientBeatInterval();
}
Also used : InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) UdpPushService(com.alibaba.nacos.naming.push.UdpPushService) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Client(com.alibaba.nacos.naming.core.v2.client.Client)

Example 9 with InstanceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata in project nacos by alibaba.

the class ClientBeatCheckTaskV2Test method testRunHealthyInstanceWithTimeoutFromMetadata.

@Test
public void testRunHealthyInstanceWithTimeoutFromMetadata() throws InterruptedException {
    injectInstance(true, System.currentTimeMillis());
    Service service = Service.newService(NAMESPACE, GROUP_NAME, SERVICE_NAME);
    InstanceMetadata metadata = new InstanceMetadata();
    metadata.getExtendData().put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, 500L);
    String address = IP + InternetAddressUtil.IP_PORT_SPLITER + PORT + InternetAddressUtil.IP_PORT_SPLITER + UtilsAndCommons.DEFAULT_CLUSTER_NAME;
    when(namingMetadataManager.getInstanceMetadata(service, address)).thenReturn(Optional.of(metadata));
    when(globalConfig.isExpireInstance()).thenReturn(true);
    TimeUnit.SECONDS.sleep(1);
    beatCheckTask.run();
    assertFalse(client.getAllInstancePublishInfo().isEmpty());
    assertFalse(client.getInstancePublishInfo(Service.newService(NAMESPACE, GROUP_NAME, SERVICE_NAME)).isHealthy());
}
Also used : InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with InstanceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata in project nacos by alibaba.

the class InstanceOperatorClientImplTest method testGetHeartBeatInterval.

@Test
public void testGetHeartBeatInterval() {
    InstanceMetadata instanceMetadata = new InstanceMetadata();
    Map<String, Object> map = new HashMap<>(2);
    instanceMetadata.setExtendData(map);
    Mockito.when(metadataManager.getInstanceMetadata(Mockito.any(), Mockito.anyString())).thenReturn(Optional.of(instanceMetadata));
    Mockito.when(switchDomain.getClientBeatInterval()).thenReturn(100L);
    long interval = instanceOperatorClient.getHeartBeatInterval("A", "C", "1.1.1.1", 8848, "D");
    Assert.assertEquals(100L, interval);
}
Also used : HashMap(java.util.HashMap) InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) Test(org.junit.Test)

Aggregations

InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)12 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)9 Instance (com.alibaba.nacos.api.naming.pojo.Instance)5 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)4 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)4 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)4 Test (org.junit.Test)4 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)2 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)2 LinkedList (java.util.LinkedList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Client (com.alibaba.nacos.naming.core.v2.client.Client)1 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)1 ServiceEvent (com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent)1 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Before (org.junit.Before)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1