Skip to content

Commit

Permalink
Merge branch 'release' into chore/visual-changes-navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu committed Dec 4, 2024
2 parents 5482fa0 + 1f07be3 commit 64fdba1
Show file tree
Hide file tree
Showing 12 changed files with 732 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public static boolean hasFiles(DatasourceConfiguration datasourceConfiguration)
}

public static List<String> getFileIds(DatasourceConfiguration datasourceConfiguration) {
if (datasourceConfiguration.getProperties() != null
if (datasourceConfiguration != null
&& datasourceConfiguration.getProperties() != null
&& datasourceConfiguration.getProperties().size() > 0) {
for (Property property : datasourceConfiguration.getProperties()) {
if (property.getKey().equalsIgnoreCase(FILES)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.external.plugins.services;

import com.appsmith.external.models.DatasourceConfiguration;
import com.appsmith.external.models.Property;
import com.external.plugins.utils.FileUtils;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

@Testcontainers
public class FileUtilTest {
@Test
public void getFileIds_withNullDatasourceConfig_returnsEmptyList() {
DatasourceConfiguration datasourceConfiguration = null;
List<String> actualFileIds = FileUtils.getFileIds(datasourceConfiguration);
assertThat(actualFileIds).isEmpty();
}

@Test
public void getFileIds_withValidDatasourceConfig_returnsFileIdList() {
DatasourceConfiguration datasourceConfiguration = new DatasourceConfiguration();
datasourceConfiguration.setUrl("https://example.com");

// create file object
Map<String, Object> fileMap = new HashMap<String, Object>();
fileMap.put("id", "fileId");
fileMap.put("name", "fileName");
fileMap.put("size", 10);
fileMap.put("mimetype", "fileMimetype");

Property property = new Property();
property.setKey("Files");
property.setValue(List.of(fileMap));

datasourceConfiguration.setProperties(List.of(property));
List<String> actualFileIds = FileUtils.getFileIds(datasourceConfiguration);
assertThat(actualFileIds).contains("fileId");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,9 @@ public Application getNewArtifact(String workspaceId, String repoName) {
newApplication.setGitApplicationMetadata(new GitArtifactMetadata());
return newApplication;
}

@Override
public Mono<Application> publishArtifactPostCommit(Artifact committedArtifact) {
return publishArtifact(committedArtifact, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ public class GitRedisUtils {
private final RedisUtils redisUtils;
private final ObservationRegistry observationRegistry;

public Mono<Boolean> addFileLock(String defaultApplicationId, String commandName, Boolean isRetryAllowed) {
/**
* Adds a baseArtifact id as a key in redis, the presence of this key represents a symbolic lock, essentially meaning that no new operations
* should be performed till this key remains present.
* @param baseArtifactId : base id of the artifact for which the key is getting added.
* @param commandName : Name of the operation which is trying to acquire the lock, this value will be added against the key
* @param isRetryAllowed : Boolean for whether retries for adding the value is allowed
* @return a boolean publisher for the added file locks
*/
public Mono<Boolean> addFileLock(String baseArtifactId, 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);
log.info("Git command {} is trying to acquire the lock for application id {}", commandName, baseArtifactId);
return redisUtils
.addFileLock(defaultApplicationId, commandName)
.addFileLock(baseArtifactId, commandName)
.retryWhen(Retry.fixedDelay(numberOfRetries, RETRY_DELAY)
.onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> {
if (retrySignal.failure() instanceof AppsmithException) {
Expand All @@ -54,4 +59,38 @@ public Mono<Boolean> releaseFileLock(String defaultApplicationId) {
.name(GitSpan.RELEASE_FILE_LOCK)
.tap(Micrometer.observation(observationRegistry));
}

/**
* This is a wrapper method for acquiring git lock, since multiple ops are used in sequence
* for a complete composite operation not all ops require to acquire the lock hence a dummy flag is sent back for
* operations in that is getting executed in between
* @param baseArtifactId : id of the base artifact for which ops would be locked
* @param isLockRequired : is lock really required or is it a proxy function
* @return : Boolean for whether the lock is acquired
*/
// TODO @Manish add artifactType reference in incoming prs.
public Mono<Boolean> acquireGitLock(String baseArtifactId, String commandName, boolean isLockRequired) {
if (!Boolean.TRUE.equals(isLockRequired)) {
return Mono.just(Boolean.TRUE);
}

return addFileLock(baseArtifactId, commandName);
}

/**
* This is a wrapper method for releasing git lock, since multiple ops are used in sequence
* for a complete composite operation not all ops require to acquire the lock hence a dummy flag is sent back for
* operations in that is getting executed in between
* @param baseArtifactId : id of the base artifact for which ops would be locked
* @param isLockRequired : is lock really required or is it a proxy function
* @return : Boolean for whether the lock is released
*/
// TODO @Manish add artifactType reference in incoming prs
public Mono<Boolean> releaseFileLock(String baseArtifactId, boolean isLockRequired) {
if (!Boolean.TRUE.equals(isLockRequired)) {
return Mono.just(Boolean.TRUE);
}

return releaseFileLock(baseArtifactId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.appsmith.server.git.central;

import com.appsmith.git.dto.CommitDTO;
import com.appsmith.server.constants.ArtifactType;
import com.appsmith.server.domains.Artifact;
import com.appsmith.server.dtos.ArtifactImportDTO;
Expand All @@ -17,4 +18,7 @@ Mono<? extends Artifact> connectArtifactToGit(
String originHeader,
ArtifactType artifactType,
GitType gitType);

Mono<String> commitArtifact(
CommitDTO commitDTO, String branchedArtifactId, ArtifactType artifactType, GitType gitType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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.resolver.GitArtifactHelperResolver;
import com.appsmith.server.git.resolver.GitHandlingServiceResolver;
import com.appsmith.server.git.utils.GitAnalyticsUtils;
Expand All @@ -12,6 +13,7 @@
import com.appsmith.server.services.UserDataService;
import com.appsmith.server.services.WorkspaceService;
import com.appsmith.server.solutions.DatasourcePermission;
import io.micrometer.observation.ObservationRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

Expand All @@ -32,7 +34,9 @@ public CentralGitServiceCECompatibleImpl(
WorkspaceService workspaceService,
PluginService pluginService,
ImportService importService,
ExportService exportService) {
ExportService exportService,
GitRedisUtils gitRedisUtils,
ObservationRegistry observationRegistry) {
super(
gitProfileUtils,
gitAnalyticsUtils,
Expand All @@ -45,6 +49,8 @@ public CentralGitServiceCECompatibleImpl(
workspaceService,
pluginService,
importService,
exportService);
exportService,
gitRedisUtils,
observationRegistry);
}
}
Loading

0 comments on commit 64fdba1

Please sign in to comment.