From 4e77aa9b52db8f9f8342d853f39b9a6e941e5efc Mon Sep 17 00:00:00 2001 From: Ben Broadaway <4554569+benbroadaway@users.noreply.github.com> Date: Tue, 27 Feb 2024 10:01:56 -0600 Subject: [PATCH] concord-server: skip repository refresh when repo is disabled (#872) --- .../org/project/ProjectRepositoryManager.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/org/project/ProjectRepositoryManager.java b/server/impl/src/main/java/com/walmartlabs/concord/server/org/project/ProjectRepositoryManager.java index c5ce890de9..4433f11f4a 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/org/project/ProjectRepositoryManager.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/org/project/ProjectRepositoryManager.java @@ -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; @@ -52,6 +53,7 @@ public class ProjectRepositoryManager { private final AuditLog auditLog; private final PolicyManager policyManager; private final RepositoryRefresher repositoryRefresher; + private final TriggerManager triggerManager; @Inject public ProjectRepositoryManager(ProjectAccessManager projectAccessManager, @@ -59,7 +61,8 @@ public ProjectRepositoryManager(ProjectAccessManager projectAccessManager, RepositoryDao repositoryDao, AuditLog auditLog, PolicyManager policyManager, - RepositoryRefresher repositoryRefresher) { + RepositoryRefresher repositoryRefresher, + TriggerManager triggerManager) { this.projectAccessManager = projectAccessManager; this.secretManager = secretManager; @@ -67,6 +70,7 @@ public ProjectRepositoryManager(ProjectAccessManager projectAccessManager, this.auditLog = auditLog; this.policyManager = policyManager; this.repositoryRefresher = repositoryRefresher; + this.triggerManager = triggerManager; } public RepositoryEntry get(UUID projectId, String repositoryName) { @@ -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()); @@ -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, @@ -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)