Search in sources :

Example 1 with ConfigBatchListenRequest

use of com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest in project nacos by alibaba.

the class ConfigGrpcResourceParserTest method testParseWithConfigBatchListenRequest.

@Test
@Secured(signType = Constants.Config.CONFIG_MODULE)
public void testParseWithConfigBatchListenRequest() throws NoSuchMethodException {
    Secured secured = getMethodSecure();
    ConfigBatchListenRequest request = new ConfigBatchListenRequest();
    request.addConfigListenContext("testG", "testD", "testNs", "111");
    Resource actual = resourceParser.parse(request, secured);
    assertEquals("testNs", actual.getNamespaceId());
    assertEquals(StringUtils.EMPTY, actual.getGroup());
    assertEquals(StringUtils.EMPTY, actual.getName());
    assertEquals(Constants.Config.CONFIG_MODULE, actual.getType());
}
Also used : ConfigBatchListenRequest(com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest) Secured(com.alibaba.nacos.auth.annotation.Secured) Resource(com.alibaba.nacos.plugin.auth.api.Resource) Test(org.junit.Test) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 2 with ConfigBatchListenRequest

use of com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest in project nacos by alibaba.

the class ConfigChangeBatchListenRequestHandlerTest method testHandle.

@Test
public void testHandle() {
    String dataId = "dataId";
    String group = "group";
    String tenant = "tenant";
    String groupKey = GroupKey2.getKey(dataId, group, tenant);
    groupKey = StringPool.get(groupKey);
    when(ConfigCacheService.isUptodate(eq(groupKey), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(false);
    ConfigBatchListenRequest configChangeListenRequest = new ConfigBatchListenRequest();
    configChangeListenRequest.addConfigListenContext(group, dataId, tenant, " ");
    try {
        ConfigChangeBatchListenResponse configChangeBatchListenResponse = configQueryRequestHandler.handle(configChangeListenRequest, requestMeta);
        boolean hasChange = false;
        for (ConfigChangeBatchListenResponse.ConfigContext changedConfig : configChangeBatchListenResponse.getChangedConfigs()) {
            if (changedConfig.getDataId().equals(dataId)) {
                hasChange = true;
                break;
            }
        }
        assertTrue(hasChange);
    } catch (NacosException e) {
        e.printStackTrace();
    }
}
Also used : ConfigChangeBatchListenResponse(com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse) ConfigBatchListenRequest(com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 3 with ConfigBatchListenRequest

use of com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest in project nacos by alibaba.

the class ConfigChangeBatchListenRequestHandler method handle.

@Override
@TpsControl(pointName = "ConfigListen")
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
public ConfigChangeBatchListenResponse handle(ConfigBatchListenRequest configChangeListenRequest, RequestMeta meta) throws NacosException {
    String connectionId = StringPool.get(meta.getConnectionId());
    String tag = configChangeListenRequest.getHeader(Constants.VIPSERVER_TAG);
    ConfigChangeBatchListenResponse configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
    for (ConfigBatchListenRequest.ConfigListenContext listenContext : configChangeListenRequest.getConfigListenContexts()) {
        String groupKey = GroupKey2.getKey(listenContext.getDataId(), listenContext.getGroup(), listenContext.getTenant());
        groupKey = StringPool.get(groupKey);
        String md5 = StringPool.get(listenContext.getMd5());
        if (configChangeListenRequest.isListen()) {
            configChangeListenContext.addListen(groupKey, md5, connectionId);
            boolean isUptoDate = ConfigCacheService.isUptodate(groupKey, md5, meta.getClientIp(), tag);
            if (!isUptoDate) {
                configChangeBatchListenResponse.addChangeConfig(listenContext.getDataId(), listenContext.getGroup(), listenContext.getTenant());
            }
        } else {
            configChangeListenContext.removeListen(groupKey, connectionId);
        }
    }
    return configChangeBatchListenResponse;
}
Also used : ConfigChangeBatchListenResponse(com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse) ConfigBatchListenRequest(com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest) Secured(com.alibaba.nacos.auth.annotation.Secured) TpsControl(com.alibaba.nacos.core.remote.control.TpsControl)

Example 4 with ConfigBatchListenRequest

use of com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest in project nacos by alibaba.

the class ConfigResourceParser method parseName.

@Override
public String parseName(Object requestObj) {
    String namespaceId = null;
    String groupName = null;
    String dataId = null;
    if (requestObj instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) requestObj;
        namespaceId = NamespaceUtil.processNamespaceParameter(req.getParameter("tenant"));
        groupName = req.getParameter("group");
        dataId = req.getParameter("dataId");
    } else if (requestObj instanceof Request) {
        Request request = (Request) requestObj;
        if (request instanceof ConfigBatchListenRequest) {
            List<ConfigBatchListenRequest.ConfigListenContext> configListenContexts = ((ConfigBatchListenRequest) request).getConfigListenContexts();
            if (!configListenContexts.isEmpty()) {
                namespaceId = ((ConfigBatchListenRequest) request).getConfigListenContexts().get(0).getTenant();
            }
        } else {
            namespaceId = (String) ReflectUtils.getFieldValue(request, "tenant", "");
        }
        groupName = (String) ReflectUtils.getFieldValue(request, "group", "");
        dataId = (String) ReflectUtils.getFieldValue(request, "dataId", "");
    }
    StringBuilder sb = new StringBuilder();
    if (StringUtils.isNotBlank(namespaceId)) {
        sb.append(namespaceId);
    }
    if (StringUtils.isBlank(groupName)) {
        sb.append(Resource.SPLITTER).append('*');
    } else {
        sb.append(Resource.SPLITTER).append(groupName);
    }
    if (StringUtils.isBlank(dataId)) {
        sb.append(Resource.SPLITTER).append(AUTH_CONFIG_PREFIX).append('*');
    } else {
        sb.append(Resource.SPLITTER).append(AUTH_CONFIG_PREFIX).append(dataId);
    }
    return sb.toString();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigBatchListenRequest(com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigBatchListenRequest(com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest) Request(com.alibaba.nacos.api.remote.request.Request) List(java.util.List)

Aggregations

ConfigBatchListenRequest (com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest)4 ConfigChangeBatchListenResponse (com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse)2 Secured (com.alibaba.nacos.auth.annotation.Secured)2 Test (org.junit.Test)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Request (com.alibaba.nacos.api.remote.request.Request)1 TpsControl (com.alibaba.nacos.core.remote.control.TpsControl)1 Resource (com.alibaba.nacos.plugin.auth.api.Resource)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1