[ISSUE #2842] Fix serverStatus api jackson error
This commit is contained in:
TsingLiang 2020-05-29 17:41:17 +08:00 committed by GitHub
commit ea4a029ca4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 6 deletions

View File

@ -86,7 +86,7 @@ public class RaftController {
JsonNode json = JacksonUtils.toObj(value);
RaftPeer peer = raftCore.receivedBeat(json.get("beat"));
RaftPeer peer = raftCore.receivedBeat(JacksonUtils.toObj(json.get("beat").asText()));
return JacksonUtils.transferToJsonNode(peer);
}
@ -128,7 +128,7 @@ public class RaftController {
String value = URLDecoder.decode(entity, "UTF-8");
JsonNode json = JacksonUtils.toObj(value);
String key = json.get("key").toString();
String key = json.get("key").asText();
if (KeyBuilder.matchInstanceListKey(key)) {
raftConsistencyService.put(key, JacksonUtils.toObj(json.get("value").toString(), Instances.class));
return "ok";
@ -233,7 +233,7 @@ public class RaftController {
String value = URLDecoder.decode(entity, "UTF-8");
value = URLDecoder.decode(value, "UTF-8");
JsonNode jsonObject = JacksonUtils.createEmptyJsonNode();
JsonNode jsonObject = JacksonUtils.toObj(value);
Datum datum = JacksonUtils.toObj(jsonObject.get("datum").toString(), Datum.class);
RaftPeer source = JacksonUtils.toObj(jsonObject.get("source").toString(), RaftPeer.class);

View File

@ -288,8 +288,8 @@ public class ServiceController {
JsonNode json = JacksonUtils.toObj(value);
//format: service1@@checksum@@@service2@@checksum
String statuses = json.get("statuses").toString();
String serverIp = json.get("clientIP").toString();
String statuses = json.get("statuses").asText();
String serverIp = json.get("clientIP").asText();
if (!memberManager.hasMember(serverIp)) {
throw new NacosException(NacosException.INVALID_PARAM,

View File

@ -119,6 +119,7 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
}
}
@JsonIgnore
public HealthCheckTask getHealthCheckTask() {
return checkTask;
}

View File

@ -17,9 +17,16 @@ package com.alibaba.nacos.naming.core;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.misc.SwitchDomain.TcpHealthParams;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.ConfigurableApplicationContext;
import java.util.ArrayList;
import java.util.List;
@ -29,23 +36,34 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
/**
* @author nkorange
*/
@RunWith(MockitoJUnitRunner.class)
public class ClusterTest {
private Cluster cluster;
@Mock
private ConfigurableApplicationContext context;
@Mock
private SwitchDomain switchDomain;
@Before
public void before() {
ApplicationUtils.injectContext(context);
when(context.getBean(SwitchDomain.class)).thenReturn(switchDomain);
when(switchDomain.getTcpHealthParams()).thenReturn(new TcpHealthParams());
Service service = new Service();
service.setName("nacos.service.1");
cluster = new Cluster("nacos-cluster-1", service);
cluster.setDefCkport(80);
cluster.setDefIPPort(8080);
cluster.init();
}