-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: Add cleanup and update stage for tenant at the server restart #35786
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
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
183605f
chore: Add cleanup and update stage for tenant at the server restart
abhvsn 142d988
chore: Add the reactive call in bean creation
abhvsn f7f5184
chore: Revert mono call
abhvsn 2b365f5
chore: Add event listener
abhvsn a475a80
chore: Make method private
abhvsn 110f514
fix: Testcases for consolidatedAPI
abhvsn 36534dd
chore: Add cache eviction step
abhvsn fc4058a
chore: Add comment
abhvsn e288cfe
chore: Update with constant
abhvsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...server/appsmith-server/src/main/java/com/appsmith/server/configurations/TenantConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.appsmith.server.configurations; | ||
|
|
||
| import com.appsmith.server.domains.Tenant; | ||
| import com.appsmith.server.helpers.CollectionUtils; | ||
| import com.appsmith.server.repositories.CacheableRepositoryHelper; | ||
| import com.appsmith.server.repositories.TenantRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.boot.context.event.ApplicationStartedEvent; | ||
| import org.springframework.context.ApplicationListener; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import static com.appsmith.external.models.BaseDomain.policySetToMap; | ||
|
|
||
| @Configuration | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class TenantConfig implements ApplicationListener<ApplicationStartedEvent> { | ||
|
|
||
| private final TenantRepository tenantRepository; | ||
| private final CacheableRepositoryHelper cachableRepositoryHelper; | ||
|
|
||
| // Method to cleanup the cache and update the default tenant policies if the policyMap is empty. This will make sure | ||
| // cache will be updated if we update the tenant via startup DB migrations. | ||
| // As we have mocked the TenantService in the tests, we had to manually evict the cache and save the object to DB | ||
| private Mono<Tenant> cleanupAndUpdateRefreshDefaultTenantPolicies() { | ||
| log.debug("Cleaning up and updating default tenant policies on server startup"); | ||
| return tenantRepository.findBySlug("default").flatMap(tenant -> { | ||
| if (CollectionUtils.isNullOrEmpty(tenant.getPolicyMap())) { | ||
| tenant.setPolicyMap(policySetToMap(tenant.getPolicies())); | ||
| return cachableRepositoryHelper | ||
| .evictCachedTenant(tenant.getId()) | ||
| .then(tenantRepository.save(tenant)); | ||
| } | ||
| return Mono.just(tenant); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void onApplicationEvent(ApplicationStartedEvent event) { | ||
| cleanupAndUpdateRefreshDefaultTenantPolicies().block(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.