Search in sources :

Example 1 with GroupkeyListenserStatus

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"));
}
Also used : GroupkeyListenserStatus(com.alibaba.nacos.config.server.model.GroupkeyListenserStatus) HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with GroupkeyListenserStatus

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"));
}
Also used : GroupkeyListenserStatus(com.alibaba.nacos.config.server.model.GroupkeyListenserStatus) HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) Test(org.junit.Test)

Example 3 with GroupkeyListenserStatus

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;
}
Also used : GroupkeyListenserStatus(com.alibaba.nacos.config.server.model.GroupkeyListenserStatus) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 4 with GroupkeyListenserStatus

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;
}
Also used : GroupkeyListenserStatus(com.alibaba.nacos.config.server.model.GroupkeyListenserStatus) HashMap(java.util.HashMap) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

GroupkeyListenserStatus (com.alibaba.nacos.config.server.model.GroupkeyListenserStatus)4 SampleResult (com.alibaba.nacos.config.server.model.SampleResult)4 HashMap (java.util.HashMap)3 Test (org.junit.Test)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Secured (com.alibaba.nacos.auth.annotation.Secured)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ModelMap (org.springframework.ui.ModelMap)1