Skip to content

[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

Merged

Conversation

RickonZhang0929
Copy link
Contributor

@RickonZhang0929 RickonZhang0929 commented Jul 24, 2024

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

  • 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 deployment type.
  • Update application.properties to add auth fields.

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:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

rickonzhang and others added 2 commits June 26, 2024 21:39
… 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
@CLAassistant
Copy link

CLAassistant commented Jul 24, 2024

CLA assistant check
All committers have signed the CLA.

* Fix checkstyle format

* Add configuration file fields
* @throws IOException IOException.
* @throws NacosException NacosException.
*/
@GetMapping("/configs")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configs可以抽到类的Mapping里

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已解决

@KomachiSion KomachiSion changed the base branch from develop to summer-ospp#12017 July 26, 2024 09:43
* Update ConsoleConfigController route
* Delete unnecessary comments
* @author zhangyukun
*/
@RestController
@RequestMapping("/v3/console/cs/configs")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uri需要用复数形式吗?

Copy link
Contributor Author

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,
Copy link
Collaborator

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

Copy link
Contributor Author

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
Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controller层一般情况下会要做的事:

  1. 参数类型的转换和封装
  2. 参数有效性的校验
  3. 返回内容的转换和封装。

目前提交的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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新接口最好统一用namespaceId替换tenant

Copy link
Contributor Author

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

错误码需要判断是否是已知的问题,比如NacosException或者NacosRuntimeException等。

如果这里不确定的话, 就不要做异常处理, 交给ExceptionHandler来统一处理。

Copy link
Contributor Author

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么不直接在方法上用ConfigForm?

Copy link
Contributor Author

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();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解密应该算是业务逻辑了,其他的发布配置的时候也是在controller里面吗?

Copy link
Contributor Author

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.
Copy link
Collaborator

@KomachiSion KomachiSion left a 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是少了AdminAPI的指定

Copy link
Contributor Author

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConfig却不返回内容吗? 是不是有错误?

Copy link
Contributor Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是鉴权的开关?

Copy link
Contributor Author

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
@RickonZhang0929
Copy link
Contributor Author

proxy和controller的命名看下是否调整一下, 有几个method和api我看着有点难理解。

命名已调整

Copy link
Collaborator

@KomachiSion KomachiSion left a 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.");
Copy link
Collaborator

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
Copy link
Collaborator

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
@KomachiSion KomachiSion merged commit 95e9a22 into alibaba:summer-ospp#12017 Aug 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants