diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java index c26ec3c2a2e9..c224046d1ad5 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/GitConstants.java @@ -5,4 +5,6 @@ public class GitConstants extends GitConstantsCE { public class GitMetricConstants extends GitMetricConstantsCE {} + + public class GitCommandConstants extends GitCommandConstantsCE {} } diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/GitConstantsCE.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/GitConstantsCE.java index 5b5a10969efb..8fd9d3d88178 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/GitConstantsCE.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/GitConstantsCE.java @@ -31,4 +31,21 @@ public class GitMetricConstantsCE { public static final String ACTION_COLLECTION_BODY = "ActionCollectionBody"; public static final String NEW_ACTION_BODY = "NewActionBody"; } + + public class GitCommandConstantsCE { + public static final String METADATA = "metadata"; + public static final String AUTO_COMMIT = "autoCommit"; + public static final String PULL = "pull"; + public static final String PUSH = "push"; + public static final String STATUS = "status"; + public static final String FETCH_REMOTE = "fetchRemote"; + public static final String COMMIT = "commit"; + public static final String CREATE_BRANCH = "createBranch"; + public static final String CHECKOUT_BRANCH = "checkoutBranch"; + public static final String SYNC_BRANCH = "syncBranch"; + public static final String LIST_BRANCH = "listBranch"; + public static final String MERGE_BRANCH = "mergeBranch"; + public static final String DELETE = "delete"; + public static final String DISCARD = "discard"; + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java index 6e386d10f3b4..f289ab9925cd 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java @@ -855,7 +855,7 @@ public enum AppsmithError { GIT_FILE_IN_USE( 500, AppsmithErrorCode.GIT_FILE_IN_USE.getCode(), - "We were unable to place a lock on the file system to perform #commandName command. This error can occur when another operation is in progress. Please try again later.", + "We were unable to place a lock on the file system to perform {0} command. This error can occur when another command {1}, which is in progress. Please try again later.", AppsmithErrorAction.DEFAULT, "Git repo is locked", ErrorType.GIT_ACTION_EXECUTION_ERROR, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerCEImpl.java index 2bb52698ac40..f51bd5dac258 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerCEImpl.java @@ -3,6 +3,7 @@ import com.appsmith.external.constants.AnalyticsEvents; import com.appsmith.external.dtos.ModifiedResources; import com.appsmith.external.git.GitExecutor; +import com.appsmith.external.git.constants.GitConstants.GitCommandConstants; import com.appsmith.server.configurations.ProjectProperties; import com.appsmith.server.constants.ArtifactType; import com.appsmith.server.constants.FieldName; @@ -27,7 +28,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; -import reactor.util.retry.Retry; import java.nio.file.Path; import java.nio.file.Paths; @@ -38,14 +38,13 @@ import java.util.Set; import static com.appsmith.external.git.constants.GitConstants.PAGE_LIST; -import static com.appsmith.server.helpers.GitUtils.MAX_RETRIES; -import static com.appsmith.server.helpers.GitUtils.RETRY_DELAY; import static java.lang.Boolean.TRUE; @RequiredArgsConstructor @Slf4j public class AutoCommitEventHandlerCEImpl implements AutoCommitEventHandlerCE { private final ApplicationEventPublisher applicationEventPublisher; + private final GitRedisUtils gitRedisUtils; private final RedisUtils redisUtils; private final DSLMigrationUtils dslMigrationUtils; private final GitFileUtils fileUtils; @@ -84,19 +83,6 @@ public void handle(AutoCommitEvent event) { "Error during auto-commit for application: {}", event.getApplicationId(), error)); } - private Mono addFileLock(String defaultApplicationId) { - return redisUtils - .addFileLock(defaultApplicationId) - .retryWhen(Retry.fixedDelay(MAX_RETRIES, RETRY_DELAY) - .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> { - throw new AppsmithException(AppsmithError.GIT_FILE_IN_USE); - })); - } - - private Mono releaseFileLock(String defaultApplicationId) { - return redisUtils.releaseFileLock(defaultApplicationId); - } - private Mono setProgress(T result, String applicationId, int progress) { return redisUtils.setAutoCommitProgress(applicationId, progress).thenReturn(result); } @@ -133,7 +119,8 @@ private Mono saveApplicationJsonToFileSystem( } public Mono autoCommitDSLMigration(AutoCommitEvent autoCommitEvent) { - return addFileLock(autoCommitEvent.getApplicationId()) + return gitRedisUtils + .addFileLock(autoCommitEvent.getApplicationId(), GitCommandConstants.AUTO_COMMIT) .flatMap(fileLocked -> redisUtils.startAutoCommit(autoCommitEvent.getApplicationId(), autoCommitEvent.getBranchName())) .flatMap(autoCommitLocked -> dslMigrationUtils.getLatestDslVersion()) @@ -175,7 +162,7 @@ private Mono cleanUp(AutoCommitEvent autoCommitEvent, boolean isCommitM return redisUtils .finishAutoCommit(autoCommitEvent.getApplicationId()) .flatMap(r -> setProgress(r, autoCommitEvent.getApplicationId(), 100)) - .flatMap(r -> releaseFileLock(autoCommitEvent.getApplicationId())) + .flatMap(r -> gitRedisUtils.releaseFileLock(autoCommitEvent.getApplicationId())) .thenReturn(isCommitMade); } @@ -298,7 +285,8 @@ public Mono autoCommitServerMigration(AutoCommitEvent autoCommitEvent) // push to remote // release file lock - return addFileLock(defaultApplicationId) + return gitRedisUtils + .addFileLock(defaultApplicationId, GitCommandConstants.AUTO_COMMIT) .flatMap(isFileLocked -> redisUtils.startAutoCommit(defaultApplicationId, branchName)) .flatMap(r -> setProgress(r, defaultApplicationId, 10)) .flatMap(autoCommitLocked -> resetUncommittedChanges(autoCommitEvent)) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerImpl.java index b15d9f8dfc3c..ee875d550eb5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/AutoCommitEventHandlerImpl.java @@ -15,6 +15,7 @@ public class AutoCommitEventHandlerImpl extends AutoCommitEventHandlerCEImpl imp public AutoCommitEventHandlerImpl( ApplicationEventPublisher applicationEventPublisher, + GitRedisUtils gitRedisUtils, RedisUtils redisUtils, DSLMigrationUtils dslMigrationUtils, GitFileUtils fileUtils, @@ -24,6 +25,7 @@ public AutoCommitEventHandlerImpl( AnalyticsService analyticsService) { super( applicationEventPublisher, + gitRedisUtils, redisUtils, dslMigrationUtils, fileUtils, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/GitRedisUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/GitRedisUtils.java index b218de16996f..f61661f02e85 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/GitRedisUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/GitRedisUtils.java @@ -1,38 +1,57 @@ package com.appsmith.server.git; +import com.appsmith.external.git.constants.GitSpan; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.helpers.RedisUtils; +import io.micrometer.observation.ObservationRegistry; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import reactor.core.observability.micrometer.Micrometer; import reactor.core.publisher.Mono; import reactor.util.retry.Retry; import static com.appsmith.server.helpers.GitUtils.MAX_RETRIES; import static com.appsmith.server.helpers.GitUtils.RETRY_DELAY; +@Slf4j @Component @RequiredArgsConstructor public class GitRedisUtils { private final RedisUtils redisUtils; + private final ObservationRegistry observationRegistry; - public Mono addFileLock(String defaultApplicationId, Boolean isRetryAllowed) { + public Mono addFileLock(String defaultApplicationId, String commandName, Boolean isRetryAllowed) { long numberOfRetries = Boolean.TRUE.equals(isRetryAllowed) ? MAX_RETRIES : 0L; + log.info( + "Git command {} is trying to acquire the lock for application id {}", + commandName, + defaultApplicationId); return redisUtils - .addFileLock(defaultApplicationId) + .addFileLock(defaultApplicationId, commandName) .retryWhen(Retry.fixedDelay(numberOfRetries, RETRY_DELAY) .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> { - throw new AppsmithException(AppsmithError.GIT_FILE_IN_USE); - })); + if (retrySignal.failure() instanceof AppsmithException) { + throw (AppsmithException) retrySignal.failure(); + } + + throw new AppsmithException(AppsmithError.GIT_FILE_IN_USE, commandName); + })) + .name(GitSpan.ADD_FILE_LOCK) + .tap(Micrometer.observation(observationRegistry)); } - public Mono addFileLock(String defaultApplicationId) { - return addFileLock(defaultApplicationId, Boolean.TRUE); + public Mono addFileLock(String defaultApplicationId, String commandName) { + return addFileLock(defaultApplicationId, commandName, true); } public Mono releaseFileLock(String defaultApplicationId) { - return redisUtils.releaseFileLock(defaultApplicationId); + return redisUtils + .releaseFileLock(defaultApplicationId) + .name(GitSpan.RELEASE_FILE_LOCK) + .tap(Micrometer.observation(observationRegistry)); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java index ec805da90cd8..d9d6d36462bb 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java @@ -2,6 +2,7 @@ import com.appsmith.external.annotations.FeatureFlagged; import com.appsmith.external.enums.FeatureFlagEnum; +import com.appsmith.external.git.constants.GitConstants.GitCommandConstants; import com.appsmith.server.constants.ArtifactType; import com.appsmith.server.domains.GitArtifactMetadata; import com.appsmith.server.domains.Layout; @@ -55,7 +56,7 @@ public Mono isServerAutoCommitRequired(String workspaceId, GitArtifactM .defaultIfEmpty(FALSE) .cache(); - return Mono.defer(() -> gitRedisUtils.addFileLock(defaultApplicationId, FALSE)) + return Mono.defer(() -> gitRedisUtils.addFileLock(defaultApplicationId, GitCommandConstants.METADATA, false)) .then(Mono.defer(() -> isServerMigrationRequiredMonoCached)) .then(Mono.defer(() -> gitRedisUtils.releaseFileLock(defaultApplicationId))) .then(Mono.defer(() -> isServerMigrationRequiredMonoCached)) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java index 5274cd12af0d..7520cd8df236 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java @@ -9,6 +9,9 @@ import java.time.Duration; +import static com.appsmith.external.git.constants.ce.GitConstantsCE.GitCommandConstantsCE.AUTO_COMMIT; +import static org.springframework.util.StringUtils.hasText; + @Component @RequiredArgsConstructor public class RedisUtils { @@ -23,8 +26,18 @@ public class RedisUtils { private static final Duration AUTO_COMMIT_TIME_LIMIT = Duration.ofMinutes(3); - public Mono addFileLock(String key) { - return this.addFileLock(key, FILE_LOCK_TIME_LIMIT, new AppsmithException(AppsmithError.GIT_FILE_IN_USE)); + public Mono addFileLock(String key, String gitCommand) { + String command = hasText(gitCommand) ? gitCommand : REDIS_FILE_LOCK_VALUE; + return redisOperations.hasKey(key).flatMap(isKeyPresent -> { + if (!Boolean.TRUE.equals(isKeyPresent)) { + return redisOperations.opsForValue().set(key, gitCommand, FILE_LOCK_TIME_LIMIT); + } + return redisOperations + .opsForValue() + .get(key) + .flatMap(commandName -> + Mono.error(new AppsmithException(AppsmithError.GIT_FILE_IN_USE, command, commandName))); + }); } public Mono addFileLock(String key, Duration expirationPeriod, AppsmithException exception) { @@ -48,7 +61,7 @@ public Mono startAutoCommit(String defaultApplicationId, String branchN String key = String.format(AUTO_COMMIT_KEY_FORMAT, defaultApplicationId); return redisOperations.hasKey(key).flatMap(isKeyPresent -> { if (Boolean.TRUE.equals(isKeyPresent)) { - return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_IN_USE)); + return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_IN_USE, AUTO_COMMIT, AUTO_COMMIT)); } return redisOperations.opsForValue().set(key, branchName, AUTO_COMMIT_TIME_LIMIT); }); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CommonGitServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CommonGitServiceImpl.java index 479a2b3e3c1c..4128ee93893a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CommonGitServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CommonGitServiceImpl.java @@ -5,10 +5,10 @@ import com.appsmith.server.configurations.EmailConfig; import com.appsmith.server.domains.Application; import com.appsmith.server.exports.internal.ExportService; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelper; import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.GitPrivateRepoHelper; -import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.imports.internal.ImportService; import com.appsmith.server.repositories.GitDeployKeysRepository; import com.appsmith.server.services.ce_compatible.CommonGitServiceCECompatibleImpl; @@ -27,7 +27,7 @@ public CommonGitServiceImpl( GitDeployKeysRepository gitDeployKeysRepository, GitPrivateRepoHelper gitPrivateRepoHelper, CommonGitFileUtils commonGitFileUtils, - RedisUtils redisUtils, + GitRedisUtils gitRedisUtils, SessionUserService sessionUserService, UserDataService userDataService, UserService userService, @@ -44,7 +44,7 @@ public CommonGitServiceImpl( gitDeployKeysRepository, gitPrivateRepoHelper, commonGitFileUtils, - redisUtils, + gitRedisUtils, sessionUserService, userDataService, userService, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java index 4670f4f11f27..e91e39dbe0c1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java @@ -7,10 +7,10 @@ import com.appsmith.server.configurations.EmailConfig; import com.appsmith.server.datasources.base.DatasourceService; import com.appsmith.server.exports.internal.ExportService; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelper; import com.appsmith.server.helpers.GitFileUtils; import com.appsmith.server.helpers.GitPrivateRepoHelper; -import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.imports.internal.ImportService; import com.appsmith.server.newactions.base.NewActionService; @@ -54,7 +54,7 @@ public GitServiceImpl( ApplicationPermission applicationPermission, WorkspacePermission workspacePermission, WorkspaceService workspaceService, - RedisUtils redisUtils, + GitRedisUtils gitRedisUtils, ObservationRegistry observationRegistry, GitPrivateRepoHelper gitPrivateRepoHelper, TransactionalOperator transactionalOperator, @@ -82,7 +82,7 @@ public GitServiceImpl( applicationPermission, workspacePermission, workspaceService, - redisUtils, + gitRedisUtils, observationRegistry, gitPrivateRepoHelper, transactionalOperator, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java index c45b7566c59e..64fadbe83262 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/CommonGitServiceCEImpl.java @@ -8,6 +8,7 @@ import com.appsmith.external.dtos.MergeStatusDTO; import com.appsmith.external.git.GitExecutor; import com.appsmith.external.git.constants.GitConstants; +import com.appsmith.external.git.constants.GitConstants.GitCommandConstants; import com.appsmith.external.git.constants.GitSpan; import com.appsmith.server.acl.AclPermission; import com.appsmith.server.configurations.EmailConfig; @@ -35,13 +36,13 @@ import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.exports.internal.ExportService; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelper; import com.appsmith.server.helpers.CollectionUtils; import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.GitDeployKeyGenerator; import com.appsmith.server.helpers.GitPrivateRepoHelper; import com.appsmith.server.helpers.GitUtils; -import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.imports.internal.ImportService; import com.appsmith.server.repositories.GitDeployKeysRepository; import com.appsmith.server.services.AnalyticsService; @@ -70,7 +71,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.util.function.Tuple3; -import reactor.util.retry.Retry; import java.io.IOException; import java.nio.file.Path; @@ -97,8 +97,6 @@ import static com.appsmith.git.constants.AppsmithBotAsset.APPSMITH_BOT_USERNAME; import static com.appsmith.server.constants.SerialiseArtifactObjective.VERSION_CONTROL; import static com.appsmith.server.constants.ce.FieldNameCE.DEFAULT; -import static com.appsmith.server.helpers.GitUtils.MAX_RETRIES; -import static com.appsmith.server.helpers.GitUtils.RETRY_DELAY; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; import static org.apache.commons.lang.ObjectUtils.defaultIfNull; @@ -112,7 +110,7 @@ public class CommonGitServiceCEImpl implements CommonGitServiceCE { private final GitDeployKeysRepository gitDeployKeysRepository; private final GitPrivateRepoHelper gitPrivateRepoHelper; private final CommonGitFileUtils commonGitFileUtils; - private final RedisUtils redisUtils; + private final GitRedisUtils gitRedisUtils; protected final SessionUserService sessionUserService; private final UserDataService userDataService; protected final UserService userService; @@ -132,23 +130,16 @@ public class CommonGitServiceCEImpl implements CommonGitServiceCE { private static final String ORIGIN = "origin/"; private static final String REMOTE_NAME_REPLACEMENT = ""; - private Mono addFileLock(String defaultArtifactId, boolean isLockRequired) { + private Mono addFileLock(String defaultArtifactId, String commandName, boolean isLockRequired) { if (!Boolean.TRUE.equals(isLockRequired)) { return Mono.just(Boolean.TRUE); } - return Mono.defer(() -> addFileLock(defaultArtifactId)); + return Mono.defer(() -> addFileLock(defaultArtifactId, commandName)); } - private Mono addFileLock(String defaultArtifactId) { - return redisUtils - .addFileLock(defaultArtifactId) - .retryWhen(Retry.fixedDelay(MAX_RETRIES, RETRY_DELAY) - .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> { - throw new AppsmithException(AppsmithError.GIT_FILE_IN_USE); - })) - .name(GitSpan.ADD_FILE_LOCK) - .tap(Micrometer.observation(observationRegistry)); + private Mono addFileLock(String defaultArtifactId, String commandName) { + return gitRedisUtils.addFileLock(defaultArtifactId, commandName); } private Mono releaseFileLock(String defaultArtifactId, boolean isLockRequired) { @@ -160,7 +151,7 @@ private Mono releaseFileLock(String defaultArtifactId, boolean isLockRe } private Mono releaseFileLock(String defaultArtifactId) { - return redisUtils + return gitRedisUtils .releaseFileLock(defaultArtifactId) .name(GitSpan.RELEASE_FILE_LOCK) .tap(Micrometer.observation(observationRegistry)); @@ -304,7 +295,7 @@ protected Mono getStatus( Mono statusMono = Mono.zip( Mono.just(defaultGitMetadata), Mono.just(branchedArtifact), exportedArtifactJsonMono) - .flatMap(artifactAndJsonTuple3 -> addFileLock(defaultArtifactId, isFileLock) + .flatMap(artifactAndJsonTuple3 -> addFileLock(defaultArtifactId, GitCommandConstants.STATUS, isFileLock) .elapsed() .map(elapsedTuple -> { log.debug("file lock took: {}", elapsedTuple.getT1()); @@ -479,7 +470,8 @@ private Mono getStatus( return Mono.just(artifactAndJsonTuple3); } - Mono fileLockMono = Mono.defer(() -> addFileLock(defaultArtifactId)); + Mono fileLockMono = + Mono.defer(() -> addFileLock(defaultArtifactId, GitCommandConstants.STATUS)); return fileLockMono.elapsed().map(elapsedTuple -> { log.debug("file lock took: {}", elapsedTuple.getT1()); return artifactAndJsonTuple3; @@ -624,7 +616,7 @@ public Mono fetchRemoteChanges( Mono addFileLockMono = Mono.just(Boolean.TRUE); if (Boolean.TRUE.equals(isFileLock)) { - addFileLockMono = addFileLock(defaultArtifactId); + addFileLockMono = addFileLock(defaultArtifactId, GitCommandConstants.FETCH_REMOTE); } /* 1. Copy resources from DB to local repo @@ -744,7 +736,8 @@ public Mono fetchRemoteChanges( return Mono.just(tuple3); } - return addFileLock(tuple3.getT1().getDefaultArtifactId()).then(Mono.just(tuple3)); + return addFileLock(tuple3.getT1().getDefaultArtifactId(), GitCommandConstants.FETCH_REMOTE) + .then(Mono.just(tuple3)); }) .flatMap(tuple3 -> { GitArtifactMetadata defaultArtifactMetadata = tuple3.getT1(); @@ -1226,7 +1219,8 @@ private Mono commitArtifact( .flatMap(artifact -> { GitArtifactMetadata gitData = artifact.getGitArtifactMetadata(); if (Boolean.TRUE.equals(isFileLock)) { - return addFileLock(gitData.getDefaultArtifactId()).then(Mono.just(artifact)); + return addFileLock(gitData.getDefaultArtifactId(), GitCommandConstants.COMMIT) + .then(Mono.just(artifact)); } return Mono.just(artifact); }) @@ -1481,7 +1475,8 @@ protected Mono pushArtifact(Artifact branchedArtifact, boolean doPublish return Mono.just(artifact); } - return addFileLock(artifact.getGitArtifactMetadata().getDefaultArtifactId()) + return addFileLock( + artifact.getGitArtifactMetadata().getDefaultArtifactId(), GitCommandConstants.PUSH) .map(status -> artifact); }) .flatMap(artifact -> { @@ -1642,7 +1637,7 @@ protected Mono checkoutBranch(Artifact sourceArtifact, Strin gitArtifactMetadata.getDefaultArtifactId(), gitArtifactMetadata.getRepoName()); - sourceAritfactMono = addFileLock(defaultArtifactId) + sourceAritfactMono = addFileLock(defaultArtifactId, GitCommandConstants.CHECKOUT_BRANCH) .then(gitExecutor.listBranches(repoPath)) .flatMap(branchList -> releaseFileLock(defaultArtifactId).thenReturn(branchList)) .flatMap(gitBranchDTOList -> { @@ -1694,7 +1689,8 @@ private Mono checkoutRemoteBranch( Mono defaultArtifactMono = gitArtifactHelper.getArtifactById(defaultArtifactId, artifactEditPermission); - Mono checkoutRemoteBranchMono = addFileLock(defaultArtifactId) + Mono checkoutRemoteBranchMono = addFileLock( + defaultArtifactId, GitCommandConstants.CHECKOUT_BRANCH) .zipWith(defaultArtifactMono) .flatMap(tuple2 -> { Artifact artifact = tuple2.getT2(); @@ -1924,7 +1920,7 @@ public Mono createBranch( srcBranchGitData.getRepoName()); // Create a new branch from the parent checked out branch - return addFileLock(srcBranchGitData.getDefaultArtifactId()) + return addFileLock(srcBranchGitData.getDefaultArtifactId(), GitCommandConstants.CREATE_BRANCH) .flatMap(status -> gitExecutor.checkoutToBranch(repoSuffix, srcBranch)) .onErrorResume(error -> Mono.error(new AppsmithException( AppsmithError.GIT_ACTION_FAILED, "checkout", "Unable to find " + srcBranch))) @@ -2053,7 +2049,7 @@ public Mono pullArtifact(String defaultArtifactId, String branchName GitArtifactMetadata gitMetadata = defaultArtifact.getGitArtifactMetadata(); Mono statusMono = getStatus(defaultArtifact, branchedArtifact, finalBranchName, false, true); - return addFileLock(gitMetadata.getDefaultArtifactId()) + return addFileLock(gitMetadata.getDefaultArtifactId(), GitCommandConstants.PULL) .then(Mono.zip(statusMono, Mono.just(defaultArtifact), Mono.just(branchedArtifact))); }) .flatMap(tuple -> { @@ -2462,7 +2458,8 @@ public Mono deleteBranch( } return objects.getT1(); }) - .flatMap(defaultArtifact -> addFileLock(defaultArtifactId).map(status -> defaultArtifact)) + .flatMap(defaultArtifact -> addFileLock(defaultArtifactId, GitCommandConstants.DELETE) + .map(status -> defaultArtifact)) .flatMap(defaultArtifact -> { GitArtifactMetadata gitArtifactMetadata = defaultArtifact.getGitArtifactMetadata(); Path repoPath = gitArtifactHelper.getRepoSuffixPath( @@ -2550,7 +2547,8 @@ public Mono discardChanges( // Rehydrate the artifact from local file system discardChangeMono = branchedArtifactMonoCached // Add file lock before proceeding with the git operation - .flatMap(branchedArtifact -> addFileLock(defaultArtifactId).thenReturn(branchedArtifact)) + .flatMap(branchedArtifact -> addFileLock(defaultArtifactId, GitCommandConstants.DISCARD) + .thenReturn(branchedArtifact)) .flatMap(branchedArtifact -> { GitArtifactMetadata gitData = branchedArtifact.getGitArtifactMetadata(); if (gitData == null || StringUtils.isEmptyOrNull(gitData.getDefaultArtifactId())) { @@ -2633,7 +2631,8 @@ public Mono mergeBranch( Mono mergeMono = defaultArtifactMono .flatMap(defaultArtifact -> { GitArtifactMetadata gitData = defaultArtifact.getGitArtifactMetadata(); - return addFileLock(gitData.getDefaultArtifactId()).then(Mono.just(defaultArtifact)); + return addFileLock(gitData.getDefaultArtifactId(), GitCommandConstants.MERGE_BRANCH) + .then(Mono.just(defaultArtifact)); }) .flatMap(defaultArtifact -> { GitArtifactMetadata gitArtifactMetadata = defaultArtifact.getGitArtifactMetadata(); @@ -2805,7 +2804,7 @@ public Mono isBranchMergeable( // 1. Hydrate from db to file system for both branch Applications // Update function call - return addFileLock(defaultArtifactId) + return addFileLock(defaultArtifactId, GitCommandConstants.STATUS) .flatMap(status -> this.getStatus(defaultArtifactId, sourceBranch, false, artifactType)) .flatMap(srcBranchStatus -> { if (!Integer.valueOf(0).equals(srcBranchStatus.getBehindCount())) { @@ -3165,7 +3164,7 @@ protected Mono> getBranchList( private Mono syncDefaultBranchNameFromRemote(Artifact defaultArtifact, Path repoPath) { GitArtifactMetadata metadata = defaultArtifact.getGitArtifactMetadata(); GitAuth gitAuth = metadata.getGitAuth(); - return addFileLock(metadata.getDefaultArtifactId()) + return addFileLock(metadata.getDefaultArtifactId(), GitCommandConstants.SYNC_BRANCH) .then(gitExecutor.getRemoteDefaultBranch( repoPath, metadata.getRemoteUrl(), gitAuth.getPrivateKey(), gitAuth.getPublicKey())) .flatMap(defaultBranchNameInRemote -> { @@ -3298,7 +3297,7 @@ private Mono> getBranchListWithDefaultBranchName( String defaultBranchName, String currentBranch, boolean pruneBranches) { - return addFileLock(defaultArtifact.getId()) + return addFileLock(defaultArtifact.getId(), GitCommandConstants.LIST_BRANCH) .flatMap(objects -> { GitArtifactMetadata gitArtifactMetadata = defaultArtifact.getGitArtifactMetadata(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java index e18fa5108ddf..e1a78588bf5a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java @@ -8,6 +8,7 @@ import com.appsmith.external.dtos.MergeStatusDTO; import com.appsmith.external.git.GitExecutor; import com.appsmith.external.git.constants.GitConstants; +import com.appsmith.external.git.constants.GitConstants.GitCommandConstants; import com.appsmith.external.git.constants.GitSpan; import com.appsmith.external.models.Datasource; import com.appsmith.external.models.DatasourceStorage; @@ -43,13 +44,13 @@ import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.exports.internal.ExportService; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelper; import com.appsmith.server.helpers.CollectionUtils; import com.appsmith.server.helpers.GitDeployKeyGenerator; import com.appsmith.server.helpers.GitFileUtils; import com.appsmith.server.helpers.GitPrivateRepoHelper; import com.appsmith.server.helpers.GitUtils; -import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.imports.internal.ImportService; import com.appsmith.server.migrations.JsonSchemaVersions; @@ -86,7 +87,6 @@ import reactor.core.observability.micrometer.Micrometer; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import reactor.util.retry.Retry; import java.io.IOException; import java.nio.file.Path; @@ -115,8 +115,6 @@ import static com.appsmith.server.constants.FieldName.DEFAULT; import static com.appsmith.server.constants.SerialiseArtifactObjective.VERSION_CONTROL; import static com.appsmith.server.helpers.DefaultResourcesUtils.createDefaultIdsOrUpdateWithGivenResourceIds; -import static com.appsmith.server.helpers.GitUtils.MAX_RETRIES; -import static com.appsmith.server.helpers.GitUtils.RETRY_DELAY; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; import static org.apache.commons.lang.ObjectUtils.defaultIfNull; @@ -158,7 +156,7 @@ public class GitServiceCEImpl implements GitServiceCE { private final ApplicationPermission applicationPermission; private final WorkspacePermission workspacePermission; private final WorkspaceService workspaceService; - private final RedisUtils redisUtils; + private final GitRedisUtils gitRedisUtils; private final ObservationRegistry observationRegistry; private final GitPrivateRepoHelper gitPrivateRepoHelper; private final TransactionalOperator transactionalOperator; @@ -434,7 +432,8 @@ private Mono commitApplication( .flatMap(application -> { GitArtifactMetadata gitData = application.getGitApplicationMetadata(); if (TRUE.equals(isFileLock)) { - return addFileLock(gitData.getDefaultApplicationId()).then(Mono.just(application)); + return addFileLock(gitData.getDefaultApplicationId(), GitCommandConstants.COMMIT) + .then(Mono.just(application)); } return Mono.just(application); }) @@ -1021,7 +1020,8 @@ private Mono pushApplication(String applicationId, boolean doPublish, bo .flatMap(application -> { if (TRUE.equals(isFileLock)) { return addFileLock( - application.getGitApplicationMetadata().getDefaultApplicationId()) + application.getGitApplicationMetadata().getDefaultApplicationId(), + GitCommandConstants.PUSH) .map(status -> application); } return Mono.just(application); @@ -1298,7 +1298,7 @@ public Mono createBranch(String defaultApplicationId, GitBranchDTO srcBranchGitData.getRepoName()); // Create a new branch from the parent checked out branch - return addFileLock(srcBranchGitData.getDefaultApplicationId()) + return addFileLock(srcBranchGitData.getDefaultApplicationId(), GitCommandConstants.CREATE_BRANCH) .flatMap(status -> gitExecutor.checkoutToBranch(repoSuffix, srcBranch)) .onErrorResume(error -> Mono.error(new AppsmithException( AppsmithError.GIT_ACTION_FAILED, "checkout", "Unable to find " + srcBranch))) @@ -1401,7 +1401,8 @@ public Mono checkoutBranch(String defaultApplicationId, String bran getApplicationById(defaultApplicationId, applicationPermission.getEditPermission()); if (addFileLock) { rootAppMono = rootAppMono.flatMap( - application -> addFileLock(defaultApplicationId).thenReturn(application)); + application -> addFileLock(defaultApplicationId, GitCommandConstants.CHECKOUT_BRANCH) + .thenReturn(application)); } // If the user is trying to check out remote branch, create a new branch if the branch does not exist already @@ -1633,7 +1634,8 @@ public Mono pullApplication(String defaultApplicationId, String bran Mono pullMono = getApplicationById(defaultApplicationId, applicationPermission.getEditPermission()) .flatMap(application -> { GitArtifactMetadata gitData = application.getGitApplicationMetadata(); - return addFileLock(gitData.getDefaultApplicationId()).then(Mono.just(application)); + return addFileLock(gitData.getDefaultApplicationId(), GitCommandConstants.PULL) + .then(Mono.just(application)); }) .flatMap(defaultApplication -> { GitArtifactMetadata defaultGitMetadata = defaultApplication.getGitApplicationMetadata(); @@ -1758,7 +1760,7 @@ private Mono> handleRepoNotFoundException(String defaultAppli private Mono syncDefaultBranchNameFromRemote(Path repoPath, Application rootApp) { GitArtifactMetadata metadata = rootApp.getGitApplicationMetadata(); GitAuth gitAuth = metadata.getGitAuth(); - return addFileLock(metadata.getDefaultApplicationId()) + return addFileLock(metadata.getDefaultApplicationId(), GitCommandConstants.SYNC_BRANCH) .then(gitExecutor.getRemoteDefaultBranch( repoPath, metadata.getRemoteUrl(), gitAuth.getPrivateKey(), gitAuth.getPublicKey())) .flatMap(defaultBranchNameInRemote -> { @@ -1839,7 +1841,7 @@ private Path getRepoPath(Application rootApplication) { private Mono> getBranchListWithDefaultBranchName( Application rootApp, Path repoPath, String defaultBranchName, String currentBranch, boolean pruneBranches) { - return addFileLock(rootApp.getId()) + return addFileLock(rootApp.getId(), GitCommandConstants.LIST_BRANCH) .flatMap(objects -> { GitArtifactMetadata gitArtifactMetadata = rootApp.getGitApplicationMetadata(); @@ -1926,7 +1928,7 @@ private Mono getStatus( .flatMap(tuple3 -> { Mono fileLockMono = Mono.empty(); if (isFileLock) { - fileLockMono = Mono.defer(() -> addFileLock(defaultApplicationId)); + fileLockMono = Mono.defer(() -> addFileLock(defaultApplicationId, GitCommandConstants.STATUS)); } return fileLockMono.thenReturn(tuple3); @@ -2086,7 +2088,9 @@ public Mono fetchRemoteChanges( .flatMap(gitApplicationMetadata -> { if (isFileLock) { // Add file lock to avoid sending wrong info on the status - return addFileLock(gitApplicationMetadata.getDefaultApplicationId()) + return addFileLock( + gitApplicationMetadata.getDefaultApplicationId(), + GitCommandConstants.FETCH_REMOTE) .then(Mono.zip(Mono.just(gitApplicationMetadata), applicationMono)); } return Mono.zip(Mono.just(gitApplicationMetadata), applicationMono); @@ -2180,7 +2184,8 @@ public Mono mergeBranch(String defaultApplicationId, GitMergeDTO defaultApplicationId, applicationPermission.getEditPermission()) .flatMap(application -> { GitArtifactMetadata gitData = application.getGitApplicationMetadata(); - return addFileLock(gitData.getDefaultApplicationId()).then(Mono.just(application)); + return addFileLock(gitData.getDefaultApplicationId(), GitCommandConstants.MERGE_BRANCH) + .then(Mono.just(application)); }) .flatMap(defaultApplication -> { GitArtifactMetadata gitArtifactMetadata = defaultApplication.getGitApplicationMetadata(); @@ -2345,7 +2350,7 @@ public Mono isBranchMergeable(String defaultApplicationId, GitMe // 1. Hydrate from db to file system for both branch Applications // Update function call - return addFileLock(defaultApplicationId) + return addFileLock(defaultApplicationId, GitCommandConstants.STATUS) .flatMap(status -> this.getStatus(defaultApplicationId, sourceBranch, false)) .flatMap(srcBranchStatus -> { if (!Integer.valueOf(0).equals(srcBranchStatus.getBehindCount())) { @@ -2840,7 +2845,8 @@ public Mono deleteBranch(String defaultApplicationId, String branch } return objects.getT1(); }) - .flatMap(application -> addFileLock(defaultApplicationId).map(status -> application)) + .flatMap(application -> addFileLock(defaultApplicationId, GitCommandConstants.DELETE) + .map(status -> application)) .flatMap(application -> { GitArtifactMetadata gitArtifactMetadata = application.getGitApplicationMetadata(); Path repoPath = Paths.get( @@ -2924,7 +2930,8 @@ public Mono discardChanges(String defaultApplicationId, String bran // Rehydrate the application from local file system discardChangeMono = branchedApplicationMono // Add file lock before proceeding with the git operation - .flatMap(application -> addFileLock(defaultApplicationId).thenReturn(application)) + .flatMap(application -> addFileLock(defaultApplicationId, GitCommandConstants.DISCARD) + .thenReturn(application)) .flatMap(branchedApplication -> { GitArtifactMetadata gitData = branchedApplication.getGitApplicationMetadata(); if (gitData == null || StringUtils.isEmptyOrNull(gitData.getDefaultApplicationId())) { @@ -3288,22 +3295,12 @@ private Mono addAnalyticsForGitOperation( .thenReturn(application)); } - private Mono addFileLock(String defaultApplicationId) { - return redisUtils - .addFileLock(defaultApplicationId) - .retryWhen(Retry.fixedDelay(MAX_RETRIES, RETRY_DELAY) - .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> { - throw new AppsmithException(AppsmithError.GIT_FILE_IN_USE); - })) - .name(GitSpan.ADD_FILE_LOCK) - .tap(Micrometer.observation(observationRegistry)); + private Mono addFileLock(String defaultApplicationId, String commandName) { + return gitRedisUtils.addFileLock(defaultApplicationId, commandName); } private Mono releaseFileLock(String defaultApplicationId) { - return redisUtils - .releaseFileLock(defaultApplicationId) - .name(GitSpan.RELEASE_FILE_LOCK) - .tap(Micrometer.observation(observationRegistry)); + return gitRedisUtils.releaseFileLock(defaultApplicationId); } @Override diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/CommonGitServiceCECompatibleImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/CommonGitServiceCECompatibleImpl.java index 9a55760d6405..5bed14486f8a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/CommonGitServiceCECompatibleImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/CommonGitServiceCECompatibleImpl.java @@ -4,10 +4,10 @@ import com.appsmith.server.configurations.EmailConfig; import com.appsmith.server.domains.Application; import com.appsmith.server.exports.internal.ExportService; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelper; import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.GitPrivateRepoHelper; -import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.imports.internal.ImportService; import com.appsmith.server.repositories.GitDeployKeysRepository; import com.appsmith.server.services.AnalyticsService; @@ -29,7 +29,7 @@ public CommonGitServiceCECompatibleImpl( GitDeployKeysRepository gitDeployKeysRepository, GitPrivateRepoHelper gitPrivateRepoHelper, CommonGitFileUtils commonGitFileUtils, - RedisUtils redisUtils, + GitRedisUtils gitRedisUtils, SessionUserService sessionUserService, UserDataService userDataService, UserService userService, @@ -46,7 +46,7 @@ public CommonGitServiceCECompatibleImpl( gitDeployKeysRepository, gitPrivateRepoHelper, commonGitFileUtils, - redisUtils, + gitRedisUtils, sessionUserService, userDataService, userService, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/GitServiceCECompatibleImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/GitServiceCECompatibleImpl.java index cf4240ab11ce..2cbd0d53efad 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/GitServiceCECompatibleImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce_compatible/GitServiceCECompatibleImpl.java @@ -6,10 +6,10 @@ import com.appsmith.server.configurations.EmailConfig; import com.appsmith.server.datasources.base.DatasourceService; import com.appsmith.server.exports.internal.ExportService; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelper; import com.appsmith.server.helpers.GitFileUtils; import com.appsmith.server.helpers.GitPrivateRepoHelper; -import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.imports.internal.ImportService; import com.appsmith.server.newactions.base.NewActionService; @@ -56,7 +56,7 @@ public GitServiceCECompatibleImpl( ApplicationPermission applicationPermission, WorkspacePermission workspacePermission, WorkspaceService workspaceService, - RedisUtils redisUtils, + GitRedisUtils gitRedisUtils, ObservationRegistry observationRegistry, GitPrivateRepoHelper gitPrivateRepoHelper, TransactionalOperator transactionalOperator, @@ -84,7 +84,7 @@ public GitServiceCECompatibleImpl( applicationPermission, workspacePermission, workspaceService, - redisUtils, + gitRedisUtils, observationRegistry, gitPrivateRepoHelper, transactionalOperator, diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java index 2e8851d7c891..10fef4cd727c 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java @@ -16,6 +16,7 @@ import com.appsmith.server.featureflags.CachedFeatures; import com.appsmith.server.git.AutoCommitEventHandler; import com.appsmith.server.git.AutoCommitEventHandlerImpl; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.DSLMigrationUtils; import com.appsmith.server.helpers.GitFileUtils; @@ -73,6 +74,9 @@ public class AutoCommitEventHandlerImplTest { @SpyBean RedisUtils redisUtils; + @SpyBean + GitRedisUtils gitRedisUtils; + @Autowired AnalyticsService analyticsService; @@ -113,6 +117,7 @@ public class AutoCommitEventHandlerImplTest { public void beforeTest() { autoCommitEventHandler = new AutoCommitEventHandlerImpl( applicationEventPublisher, + gitRedisUtils, redisUtils, dslMigrationUtils, gitFileUtils, diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java index d3692eb44e2d..6dc66baa55c7 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java @@ -2,6 +2,7 @@ import com.appsmith.external.dtos.ModifiedResources; import com.appsmith.external.enums.FeatureFlagEnum; +import com.appsmith.external.git.constants.GitConstants; import com.appsmith.server.constants.ArtifactType; import com.appsmith.server.domains.Application; import com.appsmith.server.domains.GitArtifactMetadata; @@ -10,9 +11,9 @@ import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.dtos.AutoCommitTriggerDTO; import com.appsmith.server.dtos.PageDTO; +import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.DSLMigrationUtils; -import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.services.FeatureFlagService; import com.appsmith.server.testhelpers.git.GitFileSystemTestHelper; @@ -55,7 +56,7 @@ public class AutoCommitEligibilityHelperTest { FeatureFlagService featureFlagService; @MockBean - RedisUtils redisUtils; + GitRedisUtils gitRedisUtils; @Autowired GitFileSystemTestHelper gitFileSystemTestHelper; @@ -101,8 +102,10 @@ public void beforeEach() { Mockito.when(dslMigrationUtils.getLatestDslVersion()).thenReturn(Mono.just(RANDOM_DSL_VERSION_NUMBER)); - Mockito.when(redisUtils.addFileLock(DEFAULT_APPLICATION_ID)).thenReturn(Mono.just(Boolean.TRUE)); - Mockito.when(redisUtils.releaseFileLock(DEFAULT_APPLICATION_ID)).thenReturn(Mono.just(Boolean.TRUE)); + Mockito.when(gitRedisUtils.addFileLock( + DEFAULT_APPLICATION_ID, GitConstants.GitCommandConstants.METADATA, false)) + .thenReturn(Mono.just(Boolean.TRUE)); + Mockito.when(gitRedisUtils.releaseFileLock(DEFAULT_APPLICATION_ID)).thenReturn(Mono.just(Boolean.TRUE)); } @Test