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

Portal-UI adds serverconfig configuration management of ApolloConfigDB #4680

Merged
merged 70 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
fe75b4d
add tech-support-qq-4.png
klboke May 16, 2019
99bf97a
Update README.md
klboke May 16, 2019
1579f41
Merge remote-tracking branch 'upstream/master'
klboke Nov 11, 2020
9f65eed
Merge remote-tracking branch 'upstream/master'
klboke Dec 9, 2020
d7d3fd9
Enhance the user experience in the scenario of submitting duplicate keys
klboke Dec 11, 2020
7329fab
Merge branch 'master' into master
nobodyiam Dec 12, 2020
5def448
Modify the key-value conflict exception prompt, adjust the code style
klboke Dec 12, 2020
6942564
Merge branch 'master' into master
nobodyiam Dec 12, 2020
0fc1f91
Merge remote-tracking branch 'upstream/master'
klboke Dec 19, 2020
61ad016
Merge remote-tracking branch 'origin/master'
klboke Dec 19, 2020
587ce33
rge remote-tracking branch 'upstream/master'
klboke Mar 1, 2021
9de6563
Merge remote-tracking branch 'upstream/master'
klboke Mar 8, 2021
9aab632
Merge remote-tracking branch 'upstream/master'
klboke Mar 25, 2021
050dd0a
Merge branch 'ctripcorp:master' into master
klboke May 10, 2021
5a64035
Merge branch 'master' of github.com:klboke/apollo
klboke May 10, 2021
0648fbd
Merge branch 'ctripcorp:master' into master
klboke May 19, 2021
35bd3a6
Merge branch 'master' of github.com:klboke/apollo
klboke May 19, 2021
bc8149b
Merge branch 'ctripcorp:master' into master
klboke Jun 8, 2021
e771bdd
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 8, 2021
9a1ad83
Merge branch 'ctripcorp:master' into master
klboke Jun 25, 2021
3efef37
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 25, 2021
1274281
Merge branch 'apolloconfig:master' into master
klboke Sep 1, 2021
a968932
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 1, 2021
df8942c
Merge branch 'apolloconfig:master' into master
klboke Jan 7, 2022
f98175a
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 7, 2022
710cdd6
Merge branch 'apolloconfig:master' into master
klboke Feb 18, 2022
3c162b6
Merge branch 'master' of github.com:klboke/apollo
klboke Feb 18, 2022
0101a3f
Merge branch 'apolloconfig:master' into master
klboke Jun 17, 2022
cc6f568
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 17, 2022
21dd30c
Merge branch 'apolloconfig:master' into master
klboke Jun 21, 2022
c1eeb41
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 21, 2022
e85d645
Merge branch 'apolloconfig:master' into master
klboke Jun 27, 2022
8b0056d
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 27, 2022
347e07b
Merge branch 'apolloconfig:master' into master
klboke Jul 1, 2022
d8eb437
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 1, 2022
19bae52
Merge branch 'apolloconfig:master' into master
klboke Jul 4, 2022
7e40fa1
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 4, 2022
fbbb02d
Merge branch 'apolloconfig:master' into master
klboke Jul 6, 2022
19cee24
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 6, 2022
91ba3b7
Merge branch 'apolloconfig:master' into master
klboke Jul 8, 2022
94ad542
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 8, 2022
64e1b0b
Merge branch 'apolloconfig:master' into master
klboke Jul 19, 2022
36ce5e2
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 19, 2022
c1364c2
Merge branch 'apolloconfig:master' into master
klboke Jul 22, 2022
76ed2ea
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 22, 2022
db8cf3d
Merge branch 'apolloconfig:master' into master
klboke Jul 26, 2022
3e4616d
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 26, 2022
47297cc
Merge branch 'apolloconfig:master' into master
klboke Jul 30, 2022
1c320e7
Merge branch 'apolloconfig:master' into master
klboke Aug 2, 2022
e723db5
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 2, 2022
6be6a8b
Merge branch 'apolloconfig:master' into master
klboke Aug 8, 2022
014657d
Merge branch 'apolloconfig:master' into master
klboke Aug 12, 2022
370eec9
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 12, 2022
dfa6c54
Merge branch 'apolloconfig:master' into master
klboke Sep 8, 2022
1a66d08
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 8, 2022
cb2c22e
Merge branch 'apolloconfig:master' into master
klboke Sep 14, 2022
74af869
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 14, 2022
a349f2e
Merge branch 'apolloconfig:master' into master
klboke Sep 22, 2022
7238296
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 22, 2022
c38d00d
Merge branch 'apolloconfig:master' into master
klboke Oct 8, 2022
10cbbed
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 8, 2022
601e17b
Merge branch 'apolloconfig:master' into master
klboke Oct 11, 2022
8fe2ce5
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 11, 2022
04ea7ff
Merge branch 'apolloconfig:master' into master
klboke Dec 12, 2022
cfe577c
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 12, 2022
da97b0e
feat(apollo-portal): Added serverconfig configuration management for …
klboke Dec 14, 2022
6d53524
doc(CHANGES.md): update CHANGES.md
klboke Dec 14, 2022
92e7c23
Merge branch 'master' into config
klboke Dec 14, 2022
deeadf3
Fix(CI): Fix CI check license failures
klboke Dec 14, 2022
99fc20b
feat(apollo-biz): Additional test cases
klboke Dec 14, 2022
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Apollo 2.1.0
* [feat: use can change spring.profiles.active's value without rebuild project](https://github.com/apolloconfig/apollo/pull/4616)
* [refactor: remove app.properties and move some config file's location](https://github.com/apolloconfig/apollo/pull/4637)
* [Fix the problem of deleting blank items appear at the end](https://github.com/apolloconfig/apollo/pull/4662)
* [Portal-UI adds serverConfig configuration management of ApolloConfigDB](https://github.com/apolloconfig/apollo/pull/4680)
* [Enable login authentication for eureka](https://github.com/apolloconfig/apollo/pull/4663)


------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/11?closed=1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2022 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.adminservice.controller;

import com.ctrip.framework.apollo.biz.entity.ServerConfig;
import com.ctrip.framework.apollo.biz.service.ServerConfigService;
import java.util.List;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
* @author kl (http://kailing.pub)
* @since 2022/12/13
*/
@RestController
public class ServerConfigController {
private final ServerConfigService serverConfigService;
public ServerConfigController(ServerConfigService serverConfigService) {
this.serverConfigService = serverConfigService;
}
@GetMapping("/server/config/find-all-config")
public List<ServerConfig> findAllServerConfig() {
return serverConfigService.findAll();
}

@PostMapping("/server/config")
public ServerConfig createOrUpdatePortalDBConfig(@Valid @RequestBody ServerConfig serverConfig) {
return serverConfigService.createOrUpdateConfig(serverConfig);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2022 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.adminservice.controller;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.ctrip.framework.apollo.biz.entity.ServerConfig;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;

/**
* @author kl (http://kailing.pub)
* @since 2022/12/14
*/
class ServerConfigControllerTest extends AbstractControllerTest {

@Test
@Sql(scripts = "/controller/test-server-config.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
void findAllServerConfig() {
ServerConfig[] serverConfigs = restTemplate.getForObject(url("/server/config/find-all-config"), ServerConfig[].class);
assertNotNull(serverConfigs);
assertEquals(1, serverConfigs.length);
assertEquals("name", serverConfigs[0].getKey());
assertEquals("kl", serverConfigs[0].getValue());
}

@Test
@Sql(scripts = "/controller/test-server-config.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
void createOrUpdatePortalDBConfig() {
ServerConfig serverConfig = new ServerConfig();
serverConfig.setKey("name");
serverConfig.setValue("ckl");
ServerConfig response = restTemplate.postForObject(url("/server/config"), serverConfig, ServerConfig.class);
assertNotNull(response);

ServerConfig[] serverConfigs = restTemplate.getForObject(url("/server/config/find-all-config"), ServerConfig[].class);
assertNotNull(serverConfigs);
assertEquals(1, serverConfigs.length);
assertEquals("name", serverConfigs[0].getKey());
assertEquals("ckl", serverConfigs[0].getValue());

serverConfig = new ServerConfig();
serverConfig.setKey("age");
serverConfig.setValue("30");
response = restTemplate.postForObject(url("/server/config"), serverConfig, ServerConfig.class);
assertNotNull(response);

serverConfigs = restTemplate.getForObject(url("/server/config/find-all-config"), ServerConfig[].class);
assertNotNull(serverConfigs);
assertEquals(2, serverConfigs.length);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--
-- Copyright 2022 Apollo Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`)
VALUES
('name', 'default', 'kl');
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
*/
public interface ServerConfigRepository extends PagingAndSortingRepository<ServerConfig, Long> {
ServerConfig findTopByKeyAndCluster(String key, String cluster);

ServerConfig findByKey(String key);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2022 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.biz.service;

import com.ctrip.framework.apollo.biz.entity.ServerConfig;
import com.ctrip.framework.apollo.biz.repository.ServerConfigRepository;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Objects;
import javax.transaction.Transactional;
import org.springframework.stereotype.Service;

/**
* @author kl (http://kailing.pub)
* @since 2022/12/13
*/
@Service
public class ServerConfigService {

private final ServerConfigRepository serverConfigRepository;

public ServerConfigService(ServerConfigRepository serverConfigRepository) {
this.serverConfigRepository = serverConfigRepository;
}

public List<ServerConfig> findAll() {
Iterable<ServerConfig> serverConfigs = serverConfigRepository.findAll();
return Lists.newArrayList(serverConfigs);
}

@Transactional
public ServerConfig createOrUpdateConfig(ServerConfig serverConfig) {

ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());

if (Objects.isNull(storedConfig)) {//create
serverConfig.setId(0L);//为空,设置ID 为0,jpa执行新增操作
if(Objects.isNull(serverConfig.getCluster())){
serverConfig.setCluster("default");
}
return serverConfigRepository.save(serverConfig);
}

//update
storedConfig.setComment(serverConfig.getComment());
storedConfig.setDataChangeLastModifiedBy(serverConfig.getDataChangeLastModifiedBy());
storedConfig.setValue(serverConfig.getValue());

return serverConfigRepository.save(storedConfig);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2022 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.biz.service;

import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import com.ctrip.framework.apollo.biz.entity.ServerConfig;
import java.util.List;

import static org.assertj.core.api.Assertions.*;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
* @author kl (http://kailing.pub)
* @since 2022/12/14
*/
public class ServerConfigServiceTest extends AbstractIntegrationTest {

@Autowired
private ServerConfigService serverConfigService;

@Test
public void findAll() {
List<ServerConfig> serverConfigs = serverConfigService.findAll();
assertThat(serverConfigs).isNotNull();
assertThat(serverConfigs.size()).isGreaterThanOrEqualTo(0);
}

@Test
public void createOrUpdateConfig() {
ServerConfig serverConfig = new ServerConfig();
serverConfig.setKey("name");
serverConfig.setValue("kl");
serverConfigService.createOrUpdateConfig(serverConfig);

List<ServerConfig> serverConfigs = serverConfigService.findAll();
assertThat(serverConfigs).isNotNull();
assertThat(serverConfigs.get(0).getValue()).isEqualTo("kl");
assertThat(serverConfigs.get(0).getCluster()).isEqualTo("default");
assertThat(serverConfigs.get(0).getKey()).isEqualTo("name");


serverConfig.setValue("kl2");
serverConfigService.createOrUpdateConfig(serverConfig);

serverConfigs = serverConfigService.findAll();
assertThat(serverConfigs).isNotNull();
assertThat(serverConfigs.size()).isEqualTo(1);
assertThat(serverConfigs.get(0).getValue()).isEqualTo("kl2");
assertThat(serverConfigs.get(0).getKey()).isEqualTo("name");

serverConfig = new ServerConfig();
serverConfig.setKey("name2");
serverConfig.setValue("kl2");
serverConfigService.createOrUpdateConfig(serverConfig);

serverConfigs = serverConfigService.findAll();
assertThat(serverConfigs).isNotNull();
assertThat(serverConfigs.size()).isEqualTo(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.ctrip.framework.apollo.common.dto.*;
import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
import com.ctrip.framework.apollo.portal.entity.po.ServerConfig;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.google.common.base.Joiner;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -574,5 +575,16 @@ public PageDTO<ReleaseHistoryDTO> findByPreviousReleaseIdAndOperation(Env env, l
}

}
@Service
public static class ServerConfigAPI extends API {
public List<ServerConfig> findAllConfigDBConfig(Env env){
return restTemplate.get(env, "/server/config/find-all-config", new ParameterizedTypeReference<List<ServerConfig>>() {
}).getBody();
}

public ServerConfig createOrUpdateConfigDBConfig(Env env, ServerConfig serverConfig){
return restTemplate.post(env, "/server/config", serverConfig, ServerConfig.class);
}
}

}
Loading