Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #2842] Fix serverStatus api jackson error #2918

Merged
merged 5 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public JsonNode beat(HttpServletRequest request, HttpServletResponse response) t

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);
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public String publish(HttpServletRequest request, HttpServletResponse response)
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";
Expand Down Expand Up @@ -233,7 +233,7 @@ public String onDelete(HttpServletRequest request, HttpServletResponse response)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ public String serviceStatus(HttpServletRequest request) throws Exception {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void destroy() {
}
}

@JsonIgnore
public HealthCheckTask getHealthCheckTask() {
return checkTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@

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;
Expand All @@ -29,23 +36,34 @@
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();
}


Expand Down