Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
klboke authored Mar 26, 2023
2 parents 7c7e7f0 + 5b85b42 commit 0743f96
Show file tree
Hide file tree
Showing 51 changed files with 660 additions and 208 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Apollo 2.2.0
* [Fix the problem that the deletion failure of the system rights management page does not prompt](https://github.com/apolloconfig/apollo/pull/4803)
* [Fix the issue of the system permission management page retrieving non-existent users](https://github.com/apolloconfig/apollo/pull/4802)
* [Add release history cleaning function](https://github.com/apolloconfig/apollo/pull/4813)
* [[Multi-Database Support][pg] Make JdbcUserDetailsManager compat with postgre](https://github.com/apolloconfig/apollo/pull/4790)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/13?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void requireLockAdvice(String appId, String clusterName, String namespace
public void requireLockAdvice(long itemId, String operator) {
Item item = itemService.findOne(itemId);
if (item == null){
throw new BadRequestException("item not exist.");
throw BadRequestException.itemNotExists(itemId);
}
acquireLock(item.getNamespaceId(), operator);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ void acquireLock(long namespaceId, String currentUser) {

private void acquireLock(Namespace namespace, String currentUser) {
if (namespace == null) {
throw new BadRequestException("namespace not exist.");
throw BadRequestException.namespaceNotExists();
}

long namespaceId = namespace.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void requireLockAdvice(String appId, String clusterName, String namespace
public void requireLockAdvice(long itemId, String operator) {
Item item = itemService.findOne(itemId);
if (item == null) {
throw new BadRequestException("item not exist.");
throw BadRequestException.itemNotExists(itemId);
}
tryUnlock(namespaceService.findOne(item.getNamespaceId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AppDTO create(@Valid @RequestBody AppDTO dto) {
App entity = BeanUtils.transform(App.class, dto);
App managedEntity = appService.findOne(entity.getAppId());
if (managedEntity != null) {
throw new BadRequestException("app already exist.");
throw BadRequestException.appAlreadyExists(entity.getAppId());
}

entity = adminService.createNewApp(entity);
Expand All @@ -66,7 +66,7 @@ public AppDTO create(@Valid @RequestBody AppDTO dto) {
public void delete(@PathVariable("appId") String appId, @RequestParam String operator) {
App entity = appService.findOne(appId);
if (entity == null) {
throw new NotFoundException("app not found for appId " + appId);
throw NotFoundException.appNotFound(appId);
}
adminService.deleteApp(entity, operator);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public List<AppDTO> find(@RequestParam(value = "name", required = false) String
public AppDTO get(@PathVariable("appId") String appId) {
App app = appService.findOne(appId);
if (app == null) {
throw new NotFoundException("app not found for appId " + appId);
throw NotFoundException.appNotFound(appId);
}
return BeanUtils.transform(AppDTO.class, app);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace,

entity = managedEntity;
} else {
throw new BadRequestException("app namespaces already exist.");
throw BadRequestException.appNamespaceAlreadyExists(entity.getAppId(), entity.getName());
}

return BeanUtils.transform(AppNamespaceDTO.class, entity);
Expand All @@ -80,7 +80,7 @@ public void delete(@PathVariable("appId") String appId, @PathVariable("namespace
@RequestParam String operator) {
AppNamespace entity = appNamespaceService.findOne(appId, namespaceName);
if (entity == null) {
throw new BadRequestException("app namespace not found for appId: " + appId + " namespace: " + namespaceName);
throw BadRequestException.appNamespaceNotExists(appId, namespaceName);
}
appNamespaceService.deleteAppNamespace(entity, operator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ClusterDTO create(@PathVariable("appId") String appId,
Cluster entity = BeanUtils.transform(Cluster.class, dto);
Cluster managedEntity = clusterService.findOne(appId, entity.getName());
if (managedEntity != null) {
throw new BadRequestException("cluster already exist.");
throw BadRequestException.clusterAlreadyExists(entity.getName());
}

if (autoCreatePrivateNamespace) {
Expand All @@ -69,7 +69,7 @@ public void delete(@PathVariable("appId") String appId,
Cluster entity = clusterService.findOne(appId, clusterName);

if (entity == null) {
throw new NotFoundException("cluster not found for clusterName " + clusterName);
throw NotFoundException.clusterNotFound(appId, clusterName);
}

if(ConfigConsts.CLUSTER_NAME_DEFAULT.equals(entity.getName())){
Expand All @@ -90,7 +90,7 @@ public ClusterDTO get(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) {
Cluster cluster = clusterService.findOne(appId, clusterName);
if (cluster == null) {
throw new NotFoundException("cluster not found for name " + clusterName);
throw NotFoundException.clusterNotFound(appId, clusterName);
}
return BeanUtils.transform(ClusterDTO.class, cluster);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long release
Pageable pageable) {
Release release = releaseService.findOne(releaseId);
if (release == null) {
throw new NotFoundException("release not found for %s", releaseId);
throw NotFoundException.releaseNotFound(releaseId);
}
Page<InstanceConfig> instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey
(release.getReleaseKey(), pageable);
Expand Down Expand Up @@ -123,7 +123,7 @@ public List<InstanceDTO> getByReleasesNotIn(@RequestParam("appId") String appId,
List<Release> releases = releaseService.findByReleaseIds(releaseIdSet);

if (CollectionUtils.isEmpty(releases)) {
throw new NotFoundException("releases not found for %s", releaseIds);
throw NotFoundException.releaseNotFound(releaseIds);
}

Set<String> releaseKeys = releases.stream().map(Release::getReleaseKey).collect(Collectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,13 @@ public ItemDTO create(@PathVariable("appId") String appId,

Item managedEntity = itemService.findOne(appId, clusterName, namespaceName, entity.getKey());
if (managedEntity != null) {
throw new BadRequestException("item already exists");
throw BadRequestException.itemAlreadyExists(entity.getKey());
}
entity = itemService.save(entity);
dto = BeanUtils.transform(ItemDTO.class, entity);

Commit commit = new Commit();
commit.setAppId(appId);
commit.setClusterName(clusterName);
commit.setNamespaceName(namespaceName);
commit.setChangeSets(new ConfigChangeContentBuilder().createItem(entity).build());
commit.setDataChangeCreatedBy(dto.getDataChangeLastModifiedBy());
commit.setDataChangeLastModifiedBy(dto.getDataChangeLastModifiedBy());
commitService.save(commit);
commitService.createCommit(appId, clusterName, namespaceName, new ConfigChangeContentBuilder().createItem(entity).build(),
dto.getDataChangeLastModifiedBy()
);

return dto;
}
Expand Down Expand Up @@ -128,13 +122,13 @@ public ItemDTO update(@PathVariable("appId") String appId,
@RequestBody ItemDTO itemDTO) {
Item managedEntity = itemService.findOne(itemId);
if (managedEntity == null) {
throw new NotFoundException("item not found for itemId " + itemId);
throw NotFoundException.itemNotFound(appId, clusterName, namespaceName, itemId);
}

Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
// In case someone constructs an attack scenario
if (namespace == null || namespace.getId() != managedEntity.getNamespaceId()) {
throw new BadRequestException("Invalid request, item and namespace do not match!");
throw BadRequestException.namespaceNotMatch();
}

Item entity = BeanUtils.transform(Item.class, itemDTO);
Expand All @@ -154,14 +148,7 @@ public ItemDTO update(@PathVariable("appId") String appId,
itemDTO = BeanUtils.transform(ItemDTO.class, entity);

if (builder.hasContent()) {
Commit commit = new Commit();
commit.setAppId(appId);
commit.setClusterName(clusterName);
commit.setNamespaceName(namespaceName);
commit.setChangeSets(builder.build());
commit.setDataChangeCreatedBy(itemDTO.getDataChangeLastModifiedBy());
commit.setDataChangeLastModifiedBy(itemDTO.getDataChangeLastModifiedBy());
commitService.save(commit);
commitService.createCommit(appId, clusterName, namespaceName, builder.build(), itemDTO.getDataChangeLastModifiedBy());
}

return itemDTO;
Expand All @@ -172,20 +159,16 @@ public ItemDTO update(@PathVariable("appId") String appId,
public void delete(@PathVariable("itemId") long itemId, @RequestParam String operator) {
Item entity = itemService.findOne(itemId);
if (entity == null) {
throw new NotFoundException("item not found for itemId " + itemId);
throw NotFoundException.itemNotFound(itemId);
}
itemService.delete(entity.getId(), operator);

Namespace namespace = namespaceService.findOne(entity.getNamespaceId());

Commit commit = new Commit();
commit.setAppId(namespace.getAppId());
commit.setClusterName(namespace.getClusterName());
commit.setNamespaceName(namespace.getNamespaceName());
commit.setChangeSets(new ConfigChangeContentBuilder().deleteItem(entity).build());
commit.setDataChangeCreatedBy(operator);
commit.setDataChangeLastModifiedBy(operator);
commitService.save(commit);
commitService.createCommit(namespace.getAppId(), namespace.getClusterName(), namespace.getNamespaceName(),
new ConfigChangeContentBuilder().deleteItem(entity).build(), operator
);

}

@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items")
Expand Down Expand Up @@ -222,7 +205,7 @@ public List<ItemDTO> findDeletedItems(@PathVariable("appId") String appId,
public ItemDTO get(@PathVariable("itemId") long itemId) {
Item item = itemService.findOne(itemId);
if (item == null) {
throw new NotFoundException("item not found for itemId " + itemId);
throw NotFoundException.itemNotFound(itemId);
}
return BeanUtils.transform(ItemDTO.class, item);
}
Expand All @@ -233,8 +216,7 @@ public ItemDTO get(@PathVariable("appId") String appId,
@PathVariable("namespaceName") String namespaceName, @PathVariable("key") String key) {
Item item = itemService.findOne(appId, clusterName, namespaceName, key);
if (item == null) {
throw new NotFoundException("item not found for %s %s %s %s", appId, clusterName,
namespaceName, key);
throw NotFoundException.itemNotFound(appId, clusterName, namespaceName, key);
}
return BeanUtils.transform(ItemDTO.class, item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ private void checkBranch(String appId, String clusterName, String namespaceName,
private void checkNamespace(String appId, String clusterName, String namespaceName) {
Namespace parentNamespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (parentNamespace == null) {
throw new BadRequestException(
"Namespace not exist. AppId = %s, ClusterName = %s, NamespaceName = %s", appId,
clusterName, namespaceName);
throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public NamespaceDTO create(@PathVariable("appId") String appId,
Namespace entity = BeanUtils.transform(Namespace.class, dto);
Namespace managedEntity = namespaceService.findOne(appId, clusterName, entity.getNamespaceName());
if (managedEntity != null) {
throw new BadRequestException("namespace already exist.");
throw BadRequestException.namespaceAlreadyExists(entity.getNamespaceName());
}

entity = namespaceService.save(entity);
Expand All @@ -68,8 +68,7 @@ public void delete(@PathVariable("appId") String appId,
@PathVariable("namespaceName") String namespaceName, @RequestParam String operator) {
Namespace entity = namespaceService.findOne(appId, clusterName, namespaceName);
if (entity == null) {
throw new NotFoundException("namespace not found for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}

namespaceService.deleteNamespace(entity, operator);
Expand All @@ -86,7 +85,7 @@ public List<NamespaceDTO> find(@PathVariable("appId") String appId,
public NamespaceDTO get(@PathVariable("namespaceId") Long namespaceId) {
Namespace namespace = namespaceService.findOne(namespaceId);
if (namespace == null) {
throw new NotFoundException("namespace not found for %s", namespaceId);
throw NotFoundException.itemNotFound(namespaceId);
}
return BeanUtils.transform(NamespaceDTO.class, namespace);
}
Expand All @@ -109,8 +108,7 @@ public NamespaceDTO get(@PathVariable("appId") String appId,
@PathVariable("namespaceName") String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("namespace not found for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}
return BeanUtils.transform(NamespaceDTO.class, namespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathV
@PathVariable String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new BadRequestException("namespace not exist.");
throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);
}

if (bizConfig.isNamespaceLockSwitchOff()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ReleaseController(
public ReleaseDTO get(@PathVariable("releaseId") long releaseId) {
Release release = releaseService.findOne(releaseId);
if (release == null) {
throw new NotFoundException("release not found for %s", releaseId);
throw NotFoundException.releaseNotFound(releaseId);
}
return BeanUtils.transform(ReleaseDTO.class, release);
}
Expand Down Expand Up @@ -125,8 +125,7 @@ public ReleaseDTO publish(@PathVariable("appId") String appId,
@RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}
Release release = releaseService.publish(namespace, releaseName, releaseComment, operator, isEmergencyPublish);

Expand Down Expand Up @@ -162,8 +161,7 @@ public ReleaseDTO updateAndPublish(@PathVariable("appId") String appId,
@RequestBody ItemChangeSets changeSets) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}

Release release = releaseService.mergeBranchChangeSetsAndRelease(namespace, branchName, releaseName,
Expand Down Expand Up @@ -214,11 +212,10 @@ public ReleaseDTO publish(@PathVariable("appId") String appId,
@RequestParam(name = "grayDelKeys") Set<String> grayDelKeys){
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}

Release release = releaseService.grayDeletionPublish(namespace, releaseName, releaseComment,
Release release = releaseService.grayDeletionPublish(namespace, releaseName, releaseComment,
operator, isEmergencyPublish, grayDelKeys);

//send release message
Expand Down
Loading

0 comments on commit 0743f96

Please sign in to comment.