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

V3.0 develop admin adi enhance and refactor. #13044

Merged
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
4 changes: 2 additions & 2 deletions common/src/main/java/com/alibaba/nacos/common/Beta.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import java.lang.annotation.Target;

/**
* Means a class is in beta version.
* Means a class or method is in beta version.
*
* @author wuzhiguo
*/
@Documented
@Target({ElementType.TYPE})
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.SOURCE)
public @interface Beta {

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
import com.alibaba.nacos.api.model.v2.Result;
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
import com.alibaba.nacos.config.server.model.form.ConfigFormV3;
import com.alibaba.nacos.config.server.paramcheck.ConfigDefaultHttpParamExtractor;
import com.alibaba.nacos.config.server.service.HistoryService;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.model.form.PageForm;
import com.alibaba.nacos.core.paramcheck.ExtractorManager;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
Expand Down Expand Up @@ -67,14 +68,15 @@ public HistoryControllerV3(HistoryService historyService) {
@GetMapping("/list")
@Secured(resource = Constants.HISTORY_CONTROLLER_V3_ADMIN_PATH, action = ActionTypes.READ,
signType = SignType.CONFIG, apiType = ApiType.ADMIN_API)
public Result<Page<ConfigHistoryInfo>> listConfigHistory(@RequestParam("dataId") String dataId,
@RequestParam("groupName") String groupName,
@RequestParam(value = "namespaceId", required = false, defaultValue = StringUtils.EMPTY) String namespaceId,
@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", required = false, defaultValue = "100") Integer pageSize) {
pageSize = Math.min(500, pageSize);
//fix issue #9783
namespaceId = NamespaceUtil.processNamespaceParameter(namespaceId);
public Result<Page<ConfigHistoryInfo>> listConfigHistory(ConfigFormV3 configForm, PageForm pageForm)
throws NacosApiException {
configForm.validate();
pageForm.validate();
int pageSize = Math.min(500, pageForm.getPageSize());
int pageNo = pageForm.getPageNo();
String dataId = configForm.getDataId();
String groupName = configForm.getGroupName();
String namespaceId = NamespaceUtil.processNamespaceParameter(configForm.getNamespaceId());
return Result.success(historyService.listConfigHistory(dataId, groupName, namespaceId, pageNo, pageSize));
}

Expand All @@ -84,11 +86,13 @@ public Result<Page<ConfigHistoryInfo>> listConfigHistory(@RequestParam("dataId")
@GetMapping
@Secured(resource = Constants.HISTORY_CONTROLLER_V3_ADMIN_PATH, action = ActionTypes.READ,
signType = SignType.CONFIG, apiType = ApiType.ADMIN_API)
public Result<ConfigHistoryInfo> getConfigHistoryInfo(@RequestParam("dataId") String dataId,
@RequestParam("groupName") String groupName,
@RequestParam(value = "namespaceId", required = false, defaultValue = StringUtils.EMPTY) String namespaceId,
@RequestParam("nid") Long nid) throws AccessException, NacosApiException {
public Result<ConfigHistoryInfo> getConfigHistoryInfo(ConfigFormV3 configForm, @RequestParam("nid") Long nid)
throws AccessException, NacosApiException {
ConfigHistoryInfo configHistoryInfo;
configForm.validate();
String dataId = configForm.getDataId();
String groupName = configForm.getGroupName();
String namespaceId = NamespaceUtil.processNamespaceParameter(configForm.getNamespaceId());
try {
//fix issue #9783
namespaceId = NamespaceUtil.processNamespaceParameter(namespaceId);
Expand All @@ -106,11 +110,13 @@ public Result<ConfigHistoryInfo> getConfigHistoryInfo(@RequestParam("dataId") St
@GetMapping(value = "/previous")
@Secured(resource = Constants.HISTORY_CONTROLLER_V3_ADMIN_PATH, action = ActionTypes.READ,
signType = SignType.CONFIG, apiType = ApiType.ADMIN_API)
public Result<ConfigHistoryInfo> getPreviousConfigHistoryInfo(@RequestParam("dataId") String dataId,
@RequestParam("groupName") String groupName,
@RequestParam(value = "namespaceId", required = false, defaultValue = StringUtils.EMPTY) String namespaceId,
@RequestParam("id") Long id) throws AccessException, NacosApiException {
public Result<ConfigHistoryInfo> getPreviousConfigHistoryInfo(ConfigFormV3 configForm, @RequestParam("id") Long id)
throws AccessException, NacosApiException {
ConfigHistoryInfo configHistoryInfo;
configForm.validate();
String dataId = configForm.getDataId();
String groupName = configForm.getGroupName();
String namespaceId = NamespaceUtil.processNamespaceParameter(configForm.getNamespaceId());
try {
//fix issue #9783.
namespaceId = NamespaceUtil.processNamespaceParameter(namespaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
import com.alibaba.nacos.plugin.auth.constant.ApiType;
import com.alibaba.nacos.plugin.auth.constant.SignType;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -66,7 +65,7 @@ public ListenerControllerV3(ConfigSubService configSubService) {
public Result<GroupkeyListenserStatus> getAllSubClientConfigByIp(@RequestParam("ip") String ip,
@RequestParam(value = "all", required = false) boolean all,
@RequestParam(value = "namespaceId", required = false) String namespaceId,
@RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime, ModelMap modelMap) {
@RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime) {
SampleResult collectSampleResult = configSubService.getCollectSampleResultByIp(ip, sampleTime);
GroupkeyListenserStatus gls = new GroupkeyListenserStatus();
gls.setCollectStatus(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class ConfigForm implements NacosForm {

private String dataId;

/**
* Deprecated, please use {@link ConfigFormV3#groupName} replaced.
*/
@Deprecated
private String group;

private String namespaceId = StringUtils.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.alibaba.nacos.api.model.v2.Result;
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
import com.alibaba.nacos.config.server.model.form.ConfigFormV3;
import com.alibaba.nacos.config.server.service.HistoryService;
import com.alibaba.nacos.core.model.form.PageForm;
import com.alibaba.nacos.persistence.model.Page;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -80,10 +82,17 @@ void testListConfigHistory() throws Exception {
page.setPagesAvailable(2);
page.setPageItems(configHistoryInfoList);

when(historyService.listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1, 10)).thenReturn(page);
when(historyService.listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1, 10)).thenReturn(
page);

Result<Page<ConfigHistoryInfo>> pageResult = historyControllerV3.listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID, 1,
10);
ConfigFormV3 configForm = new ConfigFormV3();
configForm.setDataId(TEST_DATA_ID);
configForm.setGroupName(TEST_GROUP);
configForm.setNamespaceId(TEST_NAMESPACE_ID);
PageForm pageForm = new PageForm();
pageForm.setPageNo(1);
pageForm.setPageSize(10);
Result<Page<ConfigHistoryInfo>> pageResult = historyControllerV3.listConfigHistory(configForm, pageForm);

verify(historyService).listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1, 10);

Expand Down Expand Up @@ -116,10 +125,18 @@ void testListConfigHistoryWhenNameSpaceIsPublic() throws Exception {
page.setPagesAvailable(2);
page.setPageItems(configHistoryInfoList);

when(historyService.listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1, 10)).thenReturn(page);
when(historyService.listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1, 10)).thenReturn(
page);

Result<Page<ConfigHistoryInfo>> pageResult = historyControllerV3.listConfigHistory(TEST_DATA_ID, TEST_GROUP,
TEST_NAMESPACE_ID_PUBLIC, 1, 10);
ConfigFormV3 configForm = new ConfigFormV3();
configForm.setDataId(TEST_DATA_ID);
configForm.setGroupName(TEST_GROUP);
configForm.setNamespaceId(TEST_NAMESPACE_ID_PUBLIC);
PageForm pageForm = new PageForm();
pageForm.setPageNo(1);
pageForm.setPageSize(10);

Result<Page<ConfigHistoryInfo>> pageResult = historyControllerV3.listConfigHistory(configForm, pageForm);

verify(historyService).listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1, 10);

Expand All @@ -145,9 +162,14 @@ void testGetConfigHistoryInfoWhenNameSpaceIsPublic() throws Exception {
configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime()));
configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime()));

when(historyService.getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L)).thenReturn(configHistoryInfo);
when(historyService.getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L)).thenReturn(
configHistoryInfo);

Result<ConfigHistoryInfo> result = historyControllerV3.getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L);
ConfigFormV3 configForm = new ConfigFormV3();
configForm.setDataId(TEST_DATA_ID);
configForm.setGroupName(TEST_GROUP);
configForm.setNamespaceId(TEST_NAMESPACE_ID_PUBLIC);
Result<ConfigHistoryInfo> result = historyControllerV3.getConfigHistoryInfo(configForm, 1L);

verify(historyService).getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L);

Expand All @@ -171,9 +193,14 @@ void testGetConfigHistoryInfo() throws Exception {
configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime()));
configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime()));

when(historyService.getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L)).thenReturn(configHistoryInfo);
when(historyService.getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L)).thenReturn(
configHistoryInfo);

Result<ConfigHistoryInfo> result = historyControllerV3.getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID, 1L);
ConfigFormV3 configForm = new ConfigFormV3();
configForm.setDataId(TEST_DATA_ID);
configForm.setGroupName(TEST_GROUP);
configForm.setNamespaceId(TEST_NAMESPACE_ID);
Result<ConfigHistoryInfo> result = historyControllerV3.getConfigHistoryInfo(configForm, 1L);

verify(historyService).getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L);

Expand All @@ -197,10 +224,14 @@ void testGetPreviousConfigHistoryInfo() throws Exception {
configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime()));
configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime()));

when(historyService.getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L)).thenReturn(configHistoryInfo);
when(historyService.getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC,
1L)).thenReturn(configHistoryInfo);

Result<ConfigHistoryInfo> result = historyControllerV3.getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID,
1L);
ConfigFormV3 configForm = new ConfigFormV3();
configForm.setDataId(TEST_DATA_ID);
configForm.setGroupName(TEST_GROUP);
configForm.setNamespaceId(TEST_NAMESPACE_ID);
Result<ConfigHistoryInfo> result = historyControllerV3.getPreviousConfigHistoryInfo(configForm, 1L);

verify(historyService).getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L);

Expand All @@ -224,10 +255,14 @@ void testGetPreviousConfigHistoryInfoWhenNameSpaceIsPublic() throws Exception {
configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime()));
configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime()));

when(historyService.getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L)).thenReturn(configHistoryInfo);
when(historyService.getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC,
1L)).thenReturn(configHistoryInfo);

Result<ConfigHistoryInfo> result = historyControllerV3.getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP,
TEST_NAMESPACE_ID_PUBLIC, 1L);
ConfigFormV3 configForm = new ConfigFormV3();
configForm.setDataId(TEST_DATA_ID);
configForm.setGroupName(TEST_GROUP);
configForm.setNamespaceId(TEST_NAMESPACE_ID_PUBLIC);
Result<ConfigHistoryInfo> result = historyControllerV3.getPreviousConfigHistoryInfo(configForm, 1L);

verify(historyService).getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_NAMESPACE_ID_PUBLIC, 1L);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* Kernel modules operate and maintain HTTP interfaces v3.
*
* @author yunye
* @since 3.0.0-beta
* @since 3.0.0
*/
@NacosApi
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* Cluster communication interface v3.
*
* @author yunye
* @since 3.0.0-beta
* @since 3.0.0
*/
@NacosApi
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.response.ServerLoaderInfoResponse;
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.core.cluster.Member;
import com.alibaba.nacos.core.cluster.MemberUtil;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
Expand All @@ -38,6 +37,7 @@
import com.alibaba.nacos.core.remote.ConnectionManager;
import com.alibaba.nacos.core.remote.core.ServerLoaderInfoRequestHandler;
import com.alibaba.nacos.core.remote.core.ServerReloaderRequestHandler;
import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
import com.alibaba.nacos.plugin.auth.constant.ApiType;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -64,7 +64,7 @@
* controller to control server loader v3.
*
* @author yunye
* @since 3.0.0-beta
* @since 3.0.0
*/
@NacosApi
@RestController
Expand All @@ -74,12 +74,6 @@ public class ServerLoaderControllerV3 {

private static final Logger LOGGER = LoggerFactory.getLogger(ServerLoaderControllerV3.class);

private static final String X_REAL_IP = "X-Real-IP";

private static final String X_FORWARDED_FOR = "X-Forwarded-For";

private static final String X_FORWARDED_FOR_SPLIT_SYMBOL = ",";

private final ConnectionManager connectionManager;

private final ServerMemberManager serverMemberManager;
Expand Down Expand Up @@ -138,7 +132,7 @@ public Result<String> reloadCount(@RequestParam Integer count,
public Result<String> smartReload(HttpServletRequest request,
@RequestParam(value = "loaderFactor", defaultValue = "0.1f") String loaderFactorStr) {

LOGGER.info("Smart reload request receive,requestIp={}", getRemoteIp(request));
LOGGER.info("Smart reload request receive,requestIp={}", WebUtils.getRemoteIp(request));

ServerLoaderMetrics serverLoadMetrics = getServerLoadMetrics();
List<ServerLoaderMetric> details = serverLoadMetrics.getDetail();
Expand Down Expand Up @@ -352,13 +346,4 @@ public void onException(Throwable e) {

return serverLoaderMetrics;
}

private static String getRemoteIp(HttpServletRequest request) {
String xForwardedFor = request.getHeader(X_FORWARDED_FOR);
if (!StringUtils.isBlank(xForwardedFor)) {
return xForwardedFor.split(X_FORWARDED_FOR_SPLIT_SYMBOL)[0].trim();
}
String nginxHeader = request.getHeader(X_REAL_IP);
return StringUtils.isBlank(nginxHeader) ? request.getRemoteAddr() : nginxHeader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Server loader metric summary.
*
* @author yunye
* @since 3.0.0-beta
* @since 3.0.0
*/
public class ServerLoaderMetrics {

Expand Down
Loading