-
Notifications
You must be signed in to change notification settings - Fork 13.1k
[ISSUE #12017] Add console backend configuration handling #12420
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
[ISSUE #12017] Add console backend configuration handling #12420
Conversation
… proxy and handler layers * Add ConfigHandler interface for defining configuration operations * Add ConfigInnerHandler to handle internal configuration logic * Add ConfigProxy to delegate configuration tasks based on deployment type * Add ConfigController to utilize ConfigProxy for configuration operations * Update ConsoleConfig to get development type
* Fix checkstyle format * Add configuration file fields
* @throws IOException IOException. | ||
* @throws NacosException NacosException. | ||
*/ | ||
@GetMapping("/configs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configs可以抽到类的Mapping里
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已解决
* Update ConsoleConfigController route
* Delete unnecessary comments
* @author zhangyukun | ||
*/ | ||
@RestController | ||
@RequestMapping("/v3/console/cs/configs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uri需要用复数形式吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2使用单数形式,已修改
* @throws NacosException NacosException. | ||
*/ | ||
@GetMapping("/detail") | ||
public ResponseEntity<?> detailConfigInfo(@RequestParam("dataId") String dataId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API的返回内容最好使用规范化的RestResult或者com.alibaba.nacos.api.model.v2.Result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我参考了原有代码修改返回类型
1.抛出Throwable
2.使用RestResultUtils记录成功和失败
3.使用LOGGER记录失败日志
4.根据名称填写失败信息msg
* Update ConsoleConfigController return format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Controller层一般情况下会要做的事:
- 参数类型的转换和封装
- 参数有效性的校验
- 返回内容的转换和封装。
目前提交的Controller基本都没有做到。
可以参考一下前一个同学写的ConfigControllerV2。
因为你是新增了一套新的接口,后面UI控制台会按照你新定的API进行调用, 所以很多参数、规范不必拘泥于旧接口。可以按照标准的方式去设计。
@PostMapping | ||
public RestResult<Boolean> publishConfig(HttpServletRequest request, HttpServletResponse response, | ||
@RequestParam("dataId") String dataId, @RequestParam("group") String group, | ||
@RequestParam(value = "tenant", required = false, defaultValue = "") String tenant, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新接口最好统一用namespaceId替换tenant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新的接口都已替换
return RestResultUtils.success(result); | ||
} catch (Throwable e) { | ||
LOGGER.error("publish configuration information fail", e); | ||
return RestResultUtils.failed(500, result, "publish configuration information fail"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
错误码需要判断是否是已知的问题,比如NacosException或者NacosRuntimeException等。
如果这里不确定的话, 就不要做异常处理, 交给ExceptionHandler来统一处理。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controller这里就不再异常处理了
* Update ConsoleConfigController publishConfig
ParamUtils.checkParam(dataId, group, "datumId", content); | ||
ParamUtils.checkParam(tag); | ||
|
||
ConfigForm configForm = new ConfigForm(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不直接在方法上用ConfigForm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
Pair<String, String> pair = EncryptionHandler.encryptHandler(dataId, content); | ||
content = pair.getSecond(); | ||
encryptedDataKeyFinal = pair.getFirst(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
解密应该算是业务逻辑了,其他的发布配置的时候也是在controller里面吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分下放到了handler,已修改
…tion * Added parameter validation and return value encapsulation to the Controller section * Put business operations into the handler layer * A total of 9 APIs are involved in the config section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proxy和controller的命名看下是否调整一下, 有几个method和api我看着有点难理解。
* @throws NacosApiException NacosApiException. | ||
*/ | ||
@GetMapping | ||
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是少了AdminAPI的指定
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已加上
*/ | ||
@GetMapping | ||
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG) | ||
public void getConfig(HttpServletRequest request, HttpServletResponse response, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getConfig却不返回内容吗? 是不是有错误?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已解决,这个接口更新了,替换了底层方法,有返回值了
|
||
### If turn on auth system v3: | ||
nacos.auth.console.enabled=true | ||
nacos.auth.server.enabled=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是鉴权的开关?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除,这是鉴权的开关,后面放到鉴权PR上提交
* Updating the config section backend methods
命名已调整 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最后一点小问题调整一下,
然后加一下单元测试。
|
||
NO_SELECTED_CONFIG(100006, "没有选择任何配置"), | ||
|
||
API_NOT_ALLOWED_TEMPORARILY(405, "/v3/console/core/cluster/server/leave API not allowed to use temporarily."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个接口不是配置中心的吧,而且这个接口其实不需要在v3里加。废弃了
* @throws IOException If an I/O error occurs. | ||
* @throws NacosException If a Nacos-specific error occurs. | ||
*/ | ||
@GetMapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一般来说, list接口用$parentPath/list
, 下面的detail接口,及查询配置详情的接口,直接用GET 的$parentPath
比较好
* Add unit tests for the config section * Update uri of query method
* Delete redundant error codes
Please do not create a Pull Request without creating an issue first.
What is the purpose of the change
For #12017
Add console backend configuration handling with proxy and handler layers.
Brief changelog
Verifying this change
The changes can be verified by checking the configuration handling operations in the console backend, ensuring that the proxy and handler layers function correctly based on deployment type. Additionally, verify that the authentication fields in
application.properties
are correctly utilized.Follow this checklist to help us incorporate your contribution quickly and easily:
[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
to make sure basic checks pass. Runmvn clean install -DskipITs
to make sure unit-test pass. Runmvn clean test-compile failsafe:integration-test
to make sure integration-test pass.