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());
}
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();
}
}
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;
}
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();
}
Aggregations