use of com.alibaba.nacos.config.server.model.GroupkeyListenserStatus in project nacos by alibaba.
the class ConfigControllerTest method testGetListeners.
@Test
public void testGetListeners() throws Exception {
Map<String, String> listenersGroupkeyStatus = new HashMap<>();
listenersGroupkeyStatus.put("test", "test");
SampleResult sampleResult = new SampleResult();
sampleResult.setLisentersGroupkeyStatus(listenersGroupkeyStatus);
when(configSubService.getCollectSampleResult("test", "test", "", 1)).thenReturn(sampleResult);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.CONFIG_CONTROLLER_PATH + "/listener").param("dataId", "test").param("group", "test").param("tenant", "").param("sampleTime", "1");
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
GroupkeyListenserStatus groupkeyListenserStatus = JacksonUtils.toObj(actualValue, GroupkeyListenserStatus.class);
Assert.assertEquals(200, groupkeyListenserStatus.getCollectStatus());
Assert.assertEquals(1, groupkeyListenserStatus.getLisentersGroupkeyStatus().size());
Assert.assertEquals("test", groupkeyListenserStatus.getLisentersGroupkeyStatus().get("test"));
}
use of com.alibaba.nacos.config.server.model.GroupkeyListenserStatus in project nacos by alibaba.
the class ListenerControllerTest method testGetAllSubClientConfigByIp.
@Test
public void testGetAllSubClientConfigByIp() throws Exception {
SampleResult sampleResult = new SampleResult();
Map<String, String> map = new HashMap<>();
map.put("test", "test");
sampleResult.setLisentersGroupkeyStatus(map);
when(configSubService.getCollectSampleResultByIp("localhost", 1)).thenReturn(sampleResult);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.LISTENER_CONTROLLER_PATH).param("ip", "localhost").param("all", "true").param("tenant", "test").param("sampleTime", "1");
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
GroupkeyListenserStatus groupkeyListenserStatus = JacksonUtils.toObj(actualValue, GroupkeyListenserStatus.class);
Map<String, String> resultMap = groupkeyListenserStatus.getLisentersGroupkeyStatus();
Assert.assertEquals(map.get("test"), resultMap.get("test"));
}
use of com.alibaba.nacos.config.server.model.GroupkeyListenserStatus in project nacos by alibaba.
the class ConfigController method getListeners.
/**
* Subscribe to configured client information.
*/
@GetMapping("/listener")
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
public GroupkeyListenserStatus getListeners(@RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam(value = "tenant", required = false) String tenant, @RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime) throws Exception {
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group;
SampleResult collectSampleResult = configSubService.getCollectSampleResult(dataId, group, tenant, sampleTime);
GroupkeyListenserStatus gls = new GroupkeyListenserStatus();
gls.setCollectStatus(200);
if (collectSampleResult.getLisentersGroupkeyStatus() != null) {
gls.setLisentersGroupkeyStatus(collectSampleResult.getLisentersGroupkeyStatus());
}
return gls;
}
use of com.alibaba.nacos.config.server.model.GroupkeyListenserStatus in project nacos by alibaba.
the class ListenerController method getAllSubClientConfigByIp.
/**
* Get subscribe information from client side.
*/
@GetMapping
public GroupkeyListenserStatus getAllSubClientConfigByIp(@RequestParam("ip") String ip, @RequestParam(value = "all", required = false) boolean all, @RequestParam(value = "tenant", required = false) String tenant, @RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime, ModelMap modelMap) {
SampleResult collectSampleResult = configSubService.getCollectSampleResultByIp(ip, sampleTime);
GroupkeyListenserStatus gls = new GroupkeyListenserStatus();
gls.setCollectStatus(200);
Map<String, String> configMd5Status = new HashMap<>(100);
if (collectSampleResult.getLisentersGroupkeyStatus() == null) {
return gls;
}
Map<String, String> status = collectSampleResult.getLisentersGroupkeyStatus();
for (Map.Entry<String, String> config : status.entrySet()) {
if (!StringUtils.isBlank(tenant) && config.getKey().contains(tenant)) {
configMd5Status.put(config.getKey(), config.getValue());
continue;
}
// Get common config default value, if want to get all config, you need to add "all".
if (all) {
configMd5Status.put(config.getKey(), config.getValue());
} else {
String[] configKeys = GroupKey2.parseKey(config.getKey());
if (StringUtils.isBlank(configKeys[2])) {
configMd5Status.put(config.getKey(), config.getValue());
}
}
}
gls.setLisentersGroupkeyStatus(configMd5Status);
return gls;
}
Aggregations