Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Apollo 2.5.0
* [Fix: the logical judgment for configuration addition, deletion, and modification.](https://github.com/apolloconfig/apollo/pull/5432)
* [Feature support incremental configuration synchronization client](https://github.com/apolloconfig/apollo/pull/5288)
* [optimize: Implement unified permission verification logic and Optimize the implementation of permission verification](https://github.com/apolloconfig/apollo/pull/5456)
* [CI: Add code and header formatter by spotless plugin](https://github.com/apolloconfig/apollo/pull/5485)
------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/16?closed=1)
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ We provide template files [intellij-java-google-style.xml](https://github.com/ct
* For commits, we adhere to the conventional commits format. For more details, refer to [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).

* When crafting commit messages, please adhere to the following conventions: if your commit addresses an existing issue, append "Fixes #XXX" to the end of the commit message (where XXX is the issue number).

* Before submitting a pull request, you need to run `mvn spotless:apply` locally to format the code; this is important for maintaining good coding style in the project.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,15 +27,13 @@
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableAspectJAutoProxy
@Configuration
@PropertySource(value = {"classpath:adminservice.properties"})
@EnableAutoConfiguration(exclude = {
UserDetailsServiceAutoConfiguration.class,
})
@EnableAutoConfiguration(exclude = {UserDetailsServiceAutoConfiguration.class,})
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {ApolloCommonConfig.class,
ApolloBizConfig.class,
@ComponentScan(basePackageClasses = {ApolloCommonConfig.class, ApolloBizConfig.class,
AdminServiceApplication.class})
public class AdminServiceApplication {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,8 @@ public AdminServiceAutoConfiguration(final BizConfig bizConfig) {

@Bean
public FilterRegistrationBean<AdminServiceAuthenticationFilter> adminServiceAuthenticationFilter() {
FilterRegistrationBean<AdminServiceAuthenticationFilter> filterRegistrationBean = new FilterRegistrationBean<>();
FilterRegistrationBean<AdminServiceAuthenticationFilter> filterRegistrationBean =
new FilterRegistrationBean<>();

filterRegistrationBean.setFilter(new AdminServiceAuthenticationFilter(bizConfig));
filterRegistrationBean.addUrlPatterns("/apollo/audit/*");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,10 +50,8 @@ public class NamespaceAcquireLockAspect {
private final ItemService itemService;
private final BizConfig bizConfig;

public NamespaceAcquireLockAspect(
final NamespaceLockService namespaceLockService,
final NamespaceService namespaceService,
final ItemService itemService,
public NamespaceAcquireLockAspect(final NamespaceLockService namespaceLockService,
final NamespaceService namespaceService, final ItemService itemService,
final BizConfig bizConfig) {
this.namespaceLockService = namespaceLockService;
this.namespaceService = namespaceService;
Expand All @@ -62,39 +60,38 @@ public NamespaceAcquireLockAspect(
}


//create item
// create item
@Before("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, item, ..)")
public void requireLockAdvice(String appId, String clusterName, String namespaceName,
ItemDTO item) {
ItemDTO item) {
acquireLock(appId, clusterName, namespaceName, item.getDataChangeLastModifiedBy());
}

//update item
// update item
@Before("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, itemId, item, ..)")
public void requireLockAdvice(String appId, String clusterName, String namespaceName, long itemId,
ItemDTO item) {
ItemDTO item) {
acquireLock(appId, clusterName, namespaceName, item.getDataChangeLastModifiedBy());
}

//update by change set
// update by change set
@Before("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, changeSet, ..)")
public void requireLockAdvice(String appId, String clusterName, String namespaceName,
ItemChangeSets changeSet) {
ItemChangeSets changeSet) {
acquireLock(appId, clusterName, namespaceName, changeSet.getDataChangeLastModifiedBy());
}

//delete item
// delete item
@Before("@annotation(PreAcquireNamespaceLock) && args(itemId, operator, ..)")
public void requireLockAdvice(long itemId, String operator) {
Item item = itemService.findOne(itemId);
if (item == null){
if (item == null) {
throw BadRequestException.itemNotExists(itemId);
}
acquireLock(item.getNamespaceId(), operator);
}

void acquireLock(String appId, String clusterName, String namespaceName,
String currentUser) {
void acquireLock(String appId, String clusterName, String namespaceName, String currentUser) {
if (bizConfig.isNamespaceLockSwitchOff()) {
return;
}
Expand Down Expand Up @@ -126,17 +123,17 @@ private void acquireLock(Namespace namespace, String currentUser) {
if (namespaceLock == null) {
try {
tryLock(namespaceId, currentUser);
//lock success
// lock success
} catch (DataIntegrityViolationException e) {
//lock fail
// lock fail
namespaceLock = namespaceLockService.findLock(namespaceId);
checkLock(namespace, namespaceLock, currentUser);
} catch (Exception e) {
logger.error("try lock error", e);
throw e;
}
} else {
//check lock owner is current user
// check lock owner is current user
checkLock(namespace, namespaceLock, currentUser);
}
}
Expand All @@ -149,8 +146,7 @@ private void tryLock(long namespaceId, String user) {
namespaceLockService.tryLock(lock);
}

private void checkLock(Namespace namespace, NamespaceLock namespaceLock,
String currentUser) {
private void checkLock(Namespace namespace, NamespaceLock namespaceLock, String currentUser) {
if (namespaceLock == null) {
throw new ServiceException(
String.format("Check lock for %s failed, please retry.", namespace.getNamespaceName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,12 +61,9 @@ public class NamespaceUnlockAspect {
private final ReleaseService releaseService;
private final BizConfig bizConfig;

public NamespaceUnlockAspect(
final NamespaceLockService namespaceLockService,
final NamespaceService namespaceService,
final ItemService itemService,
final ReleaseService releaseService,
final BizConfig bizConfig) {
public NamespaceUnlockAspect(final NamespaceLockService namespaceLockService,
final NamespaceService namespaceService, final ItemService itemService,
final ReleaseService releaseService, final BizConfig bizConfig) {
this.namespaceLockService = namespaceLockService;
this.namespaceService = namespaceService;
this.itemService = itemService;
Expand All @@ -75,28 +72,28 @@ public NamespaceUnlockAspect(
}


//create item
// create item
@After("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, item, ..)")
public void requireLockAdvice(String appId, String clusterName, String namespaceName,
ItemDTO item) {
ItemDTO item) {
tryUnlock(namespaceService.findOne(appId, clusterName, namespaceName));
}

//update item
// update item
@After("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, itemId, item, ..)")
public void requireLockAdvice(String appId, String clusterName, String namespaceName, long itemId,
ItemDTO item) {
ItemDTO item) {
tryUnlock(namespaceService.findOne(appId, clusterName, namespaceName));
}

//update by change set
// update by change set
@After("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, changeSet, ..)")
public void requireLockAdvice(String appId, String clusterName, String namespaceName,
ItemChangeSets changeSet) {
ItemChangeSets changeSet) {
tryUnlock(namespaceService.findOne(appId, clusterName, namespaceName));
}

//delete item
// delete item
@After("@annotation(PreAcquireNamespaceLock) && args(itemId, operator, ..)")
public void requireLockAdvice(long itemId, String operator) {
Item item = itemService.findOne(itemId);
Expand Down Expand Up @@ -125,10 +122,12 @@ boolean isModified(Namespace namespace) {
return hasNormalItems(items);
}

Map<String, String> releasedConfiguration = GSON.fromJson(release.getConfigurations(), GsonType.CONFIG);
Map<String, String> releasedConfiguration =
GSON.fromJson(release.getConfigurations(), GsonType.CONFIG);
Map<String, String> configurationFromItems = generateConfigurationFromItems(namespace, items);

MapDifference<String, String> difference = Maps.difference(releasedConfiguration, configurationFromItems);
MapDifference<String, String> difference =
Maps.difference(releasedConfiguration, configurationFromItems);

return !difference.areEqual();

Expand All @@ -144,15 +143,16 @@ private boolean hasNormalItems(List<Item> items) {
return false;
}

private Map<String, String> generateConfigurationFromItems(Namespace namespace, List<Item> namespaceItems) {
private Map<String, String> generateConfigurationFromItems(Namespace namespace,
List<Item> namespaceItems) {

Map<String, String> configurationFromItems = Maps.newHashMap();

Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
//parent namespace
// parent namespace
if (parentNamespace == null) {
generateMapFromItems(namespaceItems, configurationFromItems);
} else {//child namespace
} else {// child namespace
Release parentRelease = releaseService.findLatestActiveRelease(parentNamespace);
if (parentRelease != null) {
configurationFromItems = GSON.fromJson(parentRelease.getConfigurations(), GsonType.CONFIG);
Expand All @@ -163,7 +163,8 @@ private Map<String, String> generateConfigurationFromItems(Namespace namespace,
return configurationFromItems;
}

private Map<String, String> generateMapFromItems(List<Item> items, Map<String, String> configurationFromItems) {
private Map<String, String> generateMapFromItems(List<Item> items,
Map<String, String> configurationFromItems) {
for (Item item : items) {
String key = item.getKey();
if (StringUtils.isBlank(key)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,8 +40,7 @@ public class AccessKeyController {

private final AccessKeyService accessKeyService;

public AccessKeyController(
AccessKeyService accessKeyService) {
public AccessKeyController(AccessKeyService accessKeyService) {
this.accessKeyService = accessKeyService;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -82,7 +82,7 @@ public void update(@PathVariable String appId, @RequestBody App app) {

@GetMapping("/apps")
public List<AppDTO> find(@RequestParam(value = "name", required = false) String name,
Pageable pageable) {
Pageable pageable) {
List<App> app = null;
if (StringUtils.isBlank(name)) {
app = appService.findAll(pageable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Apollo Authors
* Copyright 2025 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,29 +43,28 @@ public class AppNamespaceController {
private final AppNamespaceService appNamespaceService;
private final NamespaceService namespaceService;

public AppNamespaceController(
final AppNamespaceService appNamespaceService,
public AppNamespaceController(final AppNamespaceService appNamespaceService,
final NamespaceService namespaceService) {
this.appNamespaceService = appNamespaceService;
this.namespaceService = namespaceService;
}

@PostMapping("/apps/{appId}/appnamespaces")
public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace,
@RequestParam(defaultValue = "false") boolean silentCreation) {
@RequestParam(defaultValue = "false") boolean silentCreation) {

AppNamespace entity = BeanUtils.transform(AppNamespace.class, appNamespace);
AppNamespace managedEntity = appNamespaceService.findOne(entity.getAppId(), entity.getName());

if (managedEntity == null) {
if (StringUtils.isEmpty(entity.getFormat())){
if (StringUtils.isEmpty(entity.getFormat())) {
entity.setFormat(ConfigFileFormat.Properties.getValue());
}

entity = appNamespaceService.createAppNamespace(entity);
} else if (silentCreation) {
appNamespaceService.createNamespaceForAppNamespaceInAllCluster(appNamespace.getAppId(), appNamespace.getName(),
appNamespace.getDataChangeCreatedBy());
appNamespaceService.createNamespaceForAppNamespaceInAllCluster(appNamespace.getAppId(),
appNamespace.getName(), appNamespace.getDataChangeCreatedBy());

entity = managedEntity;
} else {
Expand All @@ -76,8 +75,8 @@ public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace,
}

@DeleteMapping("/apps/{appId}/appnamespaces/{namespaceName:.+}")
public void delete(@PathVariable("appId") String appId, @PathVariable("namespaceName") String namespaceName,
@RequestParam String operator) {
public void delete(@PathVariable("appId") String appId,
@PathVariable("namespaceName") String namespaceName, @RequestParam String operator) {
AppNamespace entity = appNamespaceService.findOne(appId, namespaceName);
if (entity == null) {
throw BadRequestException.appNamespaceNotExists(appId, namespaceName);
Expand All @@ -86,9 +85,11 @@ public void delete(@PathVariable("appId") String appId, @PathVariable("namespace
}

@GetMapping("/appnamespaces/{publicNamespaceName}/namespaces")
public List<NamespaceDTO> findPublicAppNamespaceAllNamespaces(@PathVariable String publicNamespaceName, Pageable pageable) {
public List<NamespaceDTO> findPublicAppNamespaceAllNamespaces(
@PathVariable String publicNamespaceName, Pageable pageable) {

List<Namespace> namespaces = namespaceService.findPublicAppNamespaceAllNamespaces(publicNamespaceName, pageable);
List<Namespace> namespaces =
namespaceService.findPublicAppNamespaceAllNamespaces(publicNamespaceName, pageable);

return BeanUtils.batchTransform(NamespaceDTO.class, namespaces);
}
Expand Down
Loading