fix: Clear the cache - git limit number of repos (#9874)
* Error handling for git limit * clear cahe of git limit on connect api * update per review * check the repo is public before checking for the limit * changes per review * check if the repo is public or private during connect flow
This commit is contained in:
parent
0b0b978245
commit
4f4d0fd7df
|
|
@ -13,6 +13,7 @@ public enum ErrorType {
|
|||
INTERNAL_ERROR,
|
||||
ACTION_CONFIGURATION_ERROR,
|
||||
GIT_CONFIGURATION_ERROR,
|
||||
GIT_ACTION_EXECUTION_ERROR
|
||||
GIT_ACTION_EXECUTION_ERROR,
|
||||
EE_FEATURE_ERROR
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,8 +89,6 @@ public enum AppsmithError {
|
|||
REMOVE_LAST_ORG_ADMIN_ERROR(400, 4038, "The last admin can not be removed from an organization", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR),
|
||||
INVALID_CRUD_PAGE_REQUEST(400, 4039, "Unable to process page generation request, {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST),
|
||||
UNSUPPORTED_OPERATION_FOR_REMOTE_BRANCH(400, 4040, "This operation is not supported for remote branch {0}. Please use local branches only to proceed", AppsmithErrorAction.DEFAULT, "Unsupported Operation!", ErrorType.BAD_REQUEST),
|
||||
GIT_APPLICATION_LIMIT_ERROR(400, 4041, "You have reached the maximum number of private git repo counts which can be connected to the organization. Please reach out to Appsmith support to opt for commercial plan.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR),
|
||||
|
||||
INTERNAL_SERVER_ERROR(500, 5000, "Internal server error while processing request", AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.INTERNAL_ERROR),
|
||||
REPOSITORY_SAVE_FAILED(500, 5001, "Failed to save the repository. Try again.", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR),
|
||||
PLUGIN_INSTALLATION_FAILED_DOWNLOAD_ERROR(500, 5002, "Plugin installation failed due to an error while " +
|
||||
|
|
@ -129,6 +127,7 @@ public enum AppsmithError {
|
|||
INVALID_JS_ACTION(400, 4040, "Something went wrong while trying to parse this action. Please check the JS object for errors.", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST),
|
||||
CYCLICAL_DEPENDENCY_ERROR(400, 4041, "Cyclical dependency error encountered while parsing relationship [{0}] where the relationship is denoted as (source : target).", AppsmithErrorAction.DEFAULT, "Cyclical Dependency in Page Load Actions", ErrorType.CONFIGURATION_ERROR),
|
||||
CLOUD_SERVICES_ERROR(500, 5012, "Received error from cloud services {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR),
|
||||
GIT_APPLICATION_LIMIT_ERROR(400, 4043, "You have reached the maximum number of private git repo counts which can be connected to the organization. Please reach out to Appsmith support to opt for commercial plan.", AppsmithErrorAction.DEFAULT, null, ErrorType.EE_FEATURE_ERROR),
|
||||
;
|
||||
|
||||
private final Integer httpErrorCode;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class GitServiceCEImpl implements GitServiceCE {
|
|||
private final static String MERGE_CONFLICT_BRANCH_NAME = "_mergeConflict";
|
||||
private final static String CONFLICTED_SUCCESS_MESSAGE = "branch has been created from conflicted state. Please resolve merge conflicts in remote and pull again";
|
||||
|
||||
private final static Map<Mono<String>, GitConnectionLimitDTO> gitLimitCache = new HashMap<>();
|
||||
private final static Map<String, GitConnectionLimitDTO> gitLimitCache = new HashMap<>();
|
||||
|
||||
private enum DEFAULT_COMMIT_REASONS {
|
||||
CONFLICT_STATE("for conflicted state"),
|
||||
|
|
@ -366,7 +366,7 @@ public class GitServiceCEImpl implements GitServiceCE {
|
|||
// check if the commit application will be allowed if the repo is made private
|
||||
return applicationService.save(defaultApplication)
|
||||
//Check the limit for number of private repo
|
||||
.flatMap(application -> getPrivateRepoLimitForOrg(application.getOrganizationId())
|
||||
.flatMap(application -> getPrivateRepoLimitForOrg(application.getOrganizationId(), false)
|
||||
.flatMap(limitCount -> {
|
||||
//get git connected apps count from db
|
||||
return applicationService.getGitConnectedApplicationCount(application.getOrganizationId())
|
||||
|
|
@ -554,9 +554,18 @@ public class GitServiceCEImpl implements GitServiceCE {
|
|||
)
|
||||
.then(getApplicationById(defaultApplicationId))
|
||||
//Check the limit for number of private repo
|
||||
.flatMap(application -> getPrivateRepoLimitForOrg(application.getOrganizationId())
|
||||
.flatMap(application -> {
|
||||
// Check if the repo is public
|
||||
try {
|
||||
if(!GitUtils.isRepoPrivate(GitUtils.convertSshUrlToHttpsCurlSupportedUrl(gitConnectDTO.getRemoteUrl()))) {
|
||||
return Mono.just(application);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.debug("Error while checking if the repo is private: ", e);
|
||||
}
|
||||
return getPrivateRepoLimitForOrg(application.getOrganizationId(), true)
|
||||
.flatMap(limitCount -> {
|
||||
//get git connected apps count from db
|
||||
// get git connected apps count from db
|
||||
return applicationService.getGitConnectedApplicationCount(application.getOrganizationId())
|
||||
.flatMap(count -> {
|
||||
if (limitCount <= count) {
|
||||
|
|
@ -564,7 +573,8 @@ public class GitServiceCEImpl implements GitServiceCE {
|
|||
}
|
||||
return Mono.just(application);
|
||||
});
|
||||
}))
|
||||
});
|
||||
})
|
||||
.flatMap(application -> {
|
||||
GitApplicationMetadata gitApplicationMetadata = application.getGitApplicationMetadata();
|
||||
if (isInvalidDefaultApplicationGitMetadata(application.getGitApplicationMetadata())) {
|
||||
|
|
@ -617,7 +627,6 @@ public class GitServiceCEImpl implements GitServiceCE {
|
|||
gitApplicationMetadata.setBrowserSupportedRemoteUrl(
|
||||
GitUtils.convertSshUrlToHttpsCurlSupportedUrl(gitConnectDTO.getRemoteUrl())
|
||||
);
|
||||
|
||||
try {
|
||||
gitApplicationMetadata.setIsRepoPrivate(
|
||||
GitUtils.isRepoPrivate(gitApplicationMetadata.getBrowserSupportedRemoteUrl())
|
||||
|
|
@ -714,17 +723,17 @@ public class GitServiceCEImpl implements GitServiceCE {
|
|||
});
|
||||
}
|
||||
|
||||
private Mono<Integer> getPrivateRepoLimitForOrg(String orgId) {
|
||||
private Mono<Integer> getPrivateRepoLimitForOrg(String orgId, boolean isClearCache) {
|
||||
final String baseUrl = cloudServicesConfig.getBaseUrl();
|
||||
return configService.getInstanceId().map(instanceId -> {
|
||||
if (commonConfig.isCloudHosting()) {
|
||||
return Mono.just(instanceId + "_" + orgId);
|
||||
return instanceId + "_" + orgId;
|
||||
} else {
|
||||
return Mono.just(instanceId);
|
||||
return instanceId;
|
||||
}
|
||||
}).flatMap(key -> {
|
||||
// check the cache for the repo limit
|
||||
if(gitLimitCache.containsKey(key)) {
|
||||
if(Boolean.FALSE.equals(isClearCache) && gitLimitCache.containsKey(key)) {
|
||||
return Mono.just(gitLimitCache.get(key).getRepoLimit());
|
||||
}
|
||||
// Call the cloud service API
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user