use of com.alibaba.nacos.naming.healthcheck.RsInfo in project nacos by alibaba.
the class InstanceTest method rsInfo.
@Test
public void rsInfo() throws Exception {
RsInfo info = new RsInfo();
Map<String, String> metadata = new HashMap<>();
metadata.put("version", "2222");
info.setMetadata(metadata);
System.out.println(JacksonUtils.toJson(info));
String json = JacksonUtils.toJson(info);
RsInfo info1 = JacksonUtils.toObj(json, RsInfo.class);
System.out.println(info1);
}
use of com.alibaba.nacos.naming.healthcheck.RsInfo in project nacos by alibaba.
the class InstanceOperatorClientImplTest method testHandleBeat.
@Test
public void testHandleBeat() throws NacosException {
IpPortBasedClient ipPortBasedClient = Mockito.mock(IpPortBasedClient.class);
Mockito.when(clientManager.getClient(Mockito.anyString())).thenReturn(ipPortBasedClient);
Mockito.when(ipPortBasedClient.getAllPublishedService()).thenReturn(Collections.emptyList());
int res = instanceOperatorClient.handleBeat("A", "C", "1.1.1.1", 8848, "D", new RsInfo(), BeatInfoInstanceBuilder.newBuilder());
Assert.assertEquals(NamingResponseCode.OK, res);
}
use of com.alibaba.nacos.naming.healthcheck.RsInfo in project nacos by alibaba.
the class InstanceController method beat.
/**
* Create a beat for instance.
*
* @param request http request
* @return detail information of instance
* @throws Exception any error during handle
*/
@CanDistro
@PutMapping("/beat")
@Secured(action = ActionTypes.WRITE)
public ObjectNode beat(HttpServletRequest request) throws Exception {
ObjectNode result = JacksonUtils.createEmptyJsonNode();
result.put(SwitchEntry.CLIENT_BEAT_INTERVAL, switchDomain.getClientBeatInterval());
String beat = WebUtils.optional(request, "beat", StringUtils.EMPTY);
RsInfo clientBeat = null;
if (StringUtils.isNotBlank(beat)) {
clientBeat = JacksonUtils.toObj(beat, RsInfo.class);
}
String clusterName = WebUtils.optional(request, CommonParams.CLUSTER_NAME, UtilsAndCommons.DEFAULT_CLUSTER_NAME);
String ip = WebUtils.optional(request, "ip", StringUtils.EMPTY);
int port = Integer.parseInt(WebUtils.optional(request, "port", "0"));
if (clientBeat != null) {
if (StringUtils.isNotBlank(clientBeat.getCluster())) {
clusterName = clientBeat.getCluster();
} else {
// fix #2533
clientBeat.setCluster(clusterName);
}
ip = clientBeat.getIp();
port = clientBeat.getPort();
}
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
NamingUtils.checkServiceNameFormat(serviceName);
Loggers.SRV_LOG.debug("[CLIENT-BEAT] full arguments: beat: {}, serviceName: {}, namespaceId: {}", clientBeat, serviceName, namespaceId);
BeatInfoInstanceBuilder builder = BeatInfoInstanceBuilder.newBuilder();
builder.setRequest(request);
int resultCode = getInstanceOperator().handleBeat(namespaceId, serviceName, ip, port, clusterName, clientBeat, builder);
result.put(CommonParams.CODE, resultCode);
result.put(SwitchEntry.CLIENT_BEAT_INTERVAL, getInstanceOperator().getHeartBeatInterval(namespaceId, serviceName, ip, port, clusterName));
result.put(SwitchEntry.LIGHT_BEAT_ENABLED, switchDomain.isLightBeatEnabled());
return result;
}
Aggregations