Search in sources :

Example 6 with RsInfo

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);
}
Also used : HashMap(java.util.HashMap) RsInfo(com.alibaba.nacos.naming.healthcheck.RsInfo) Test(org.junit.Test)

Example 7 with RsInfo

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);
}
Also used : RsInfo(com.alibaba.nacos.naming.healthcheck.RsInfo) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Test(org.junit.Test)

Example 8 with RsInfo

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;
}
Also used : BeatInfoInstanceBuilder(com.alibaba.nacos.naming.pojo.instance.BeatInfoInstanceBuilder) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RsInfo(com.alibaba.nacos.naming.healthcheck.RsInfo) Secured(com.alibaba.nacos.auth.annotation.Secured) PutMapping(org.springframework.web.bind.annotation.PutMapping) CanDistro(com.alibaba.nacos.naming.web.CanDistro)

Aggregations

RsInfo (com.alibaba.nacos.naming.healthcheck.RsInfo)8 Secured (com.alibaba.nacos.auth.annotation.Secured)2 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)2 BeatInfoInstanceBuilder (com.alibaba.nacos.naming.pojo.instance.BeatInfoInstanceBuilder)2 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)2 CanDistro (com.alibaba.nacos.naming.web.CanDistro)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 NacosDeserializationException (com.alibaba.nacos.api.exception.runtime.NacosDeserializationException)1 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)1 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)1 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)1 ClientBeatProcessorV2 (com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatProcessorV2)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1