Skip to content
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

server: skip repository refresh when repo is disabled #872

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.walmartlabs.concord.server.org.ResourceAccessLevel;
import com.walmartlabs.concord.server.org.secret.SecretEntry;
import com.walmartlabs.concord.server.org.secret.SecretManager;
import com.walmartlabs.concord.server.org.triggers.TriggerManager;
import com.walmartlabs.concord.server.policy.EntityAction;
import com.walmartlabs.concord.server.policy.EntityType;
import com.walmartlabs.concord.server.policy.PolicyManager;
Expand All @@ -52,21 +53,24 @@ public class ProjectRepositoryManager {
private final AuditLog auditLog;
private final PolicyManager policyManager;
private final RepositoryRefresher repositoryRefresher;
private final TriggerManager triggerManager;

@Inject
public ProjectRepositoryManager(ProjectAccessManager projectAccessManager,
SecretManager secretManager,
RepositoryDao repositoryDao,
AuditLog auditLog,
PolicyManager policyManager,
RepositoryRefresher repositoryRefresher) {
RepositoryRefresher repositoryRefresher,
TriggerManager triggerManager) {

this.projectAccessManager = projectAccessManager;
this.secretManager = secretManager;
this.repositoryDao = repositoryDao;
this.auditLog = auditLog;
this.policyManager = policyManager;
this.repositoryRefresher = repositoryRefresher;
this.triggerManager = triggerManager;
}

public RepositoryEntry get(UUID projectId, String repositoryName) {
Expand Down Expand Up @@ -103,7 +107,9 @@ public void createOrUpdate(UUID projectId, RepositoryEntry entry) {
policyManager.checkEntity(project.getOrgId(), project.getId(), EntityType.REPOSITORY, repoId == null ? EntityAction.CREATE : EntityAction.UPDATE,
null, PolicyUtils.repositoryToMap(project, entry, secret));

ProcessDefinition processDefinition = processDefinition(project.getOrgId(), projectId, entry);
ProcessDefinition processDefinition = entry.isDisabled()
? null
: processDefinition(project.getOrgId(), projectId, entry);

InsertUpdateResult result = repositoryDao.txResult(tx -> insertOrUpdate(tx, projectId, repoId, entry, secret, processDefinition));
addAuditLog(project, result.prevEntry(), result.newEntry());
Expand Down Expand Up @@ -153,6 +159,12 @@ interface InsertUpdateResult {
}

private InsertUpdateResult insertOrUpdate(DSLContext tx, UUID projectId, UUID repoId, RepositoryEntry entry, SecretEntry secret, ProcessDefinition processDefinition) {
if (!entry.isDisabled() && processDefinition == null) {
// should have already thrown and exception by this point, but just in case
// something went wrong cloning/loading process definition
throw new ConcordApplicationException("Error while loading process definition", Response.Status.INTERNAL_SERVER_ERROR);
}

RepositoryEntry prevEntry = null;
if (repoId == null) {
repoId = repositoryDao.insert(tx, projectId,
Expand All @@ -178,7 +190,11 @@ private InsertUpdateResult insertOrUpdate(DSLContext tx, UUID projectId, UUID re
entry.isTriggersDisabled());
}

repositoryRefresher.refresh(tx, projectId, entry.getName(), processDefinition);
if (entry.isDisabled()) {
triggerManager.clearTriggers(tx, projectId, repoId);
} else {
repositoryRefresher.refresh(tx, projectId, entry.getName(), processDefinition);
}

return ImmutableInsertUpdateResult.builder()
.prevEntry(prevEntry)
Expand Down
Loading