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;
}
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;
}
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();
}
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());
}
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);
}
Aggregations