From 826fef79af354f2e9bcd8863c43fe8add6af9693 Mon Sep 17 00:00:00 2001 From: Carles Arnal Date: Tue, 1 Oct 2024 11:53:32 +0200 Subject: [PATCH] Fire artifact create event inside the db transaction --- .../registry/rest/v3/GroupsResourceImpl.java | 11 ----------- .../impl/sql/AbstractSqlRegistryStorage.java | 13 +++++++++++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java b/app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java index 52159eb934..ec9950eb6d 100644 --- a/app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java +++ b/app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java @@ -67,7 +67,6 @@ import io.apicurio.registry.utils.ArtifactIdValidator; import io.quarkus.security.identity.SecurityIdentity; import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.event.Event; import jakarta.inject.Inject; import jakarta.interceptor.Interceptors; import jakarta.ws.rs.BadRequestException; @@ -126,12 +125,6 @@ public class GroupsResourceImpl extends AbstractResourceImpl implements GroupsRe @Inject SecurityIdentity securityIdentity; - @Inject - CommonResourceOperations common; - - @Inject - Event storageEvent; - public enum RegistryHashAlgorithm { SHA256, MD5 } @@ -820,10 +813,6 @@ public CreateArtifactResponse createArtifact(String groupId, IfArtifactExists if rval.setVersion(V3ApiUtil.dtoToVersionMetaData(storageResult.getRight())); } - // before returning the artifact value, fire the artifact created event. - - storageEvent.fire(ArtifactCreatedEvent.of(storageResult.getLeft())); - return rval; } catch (ArtifactAlreadyExistsException ex) { return handleIfExists(groupId, artifactId, ifExists, data.getFirstVersion(), fcanonical); diff --git a/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java b/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java index a51d48aa97..7ef54a4f42 100644 --- a/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java +++ b/app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java @@ -174,6 +174,8 @@ public abstract class AbstractSqlRegistryStorage implements RegistryStorage { @Inject SemVerConfigProperties semVerConfigProps; + @Inject + protected SqlStatements sqlStatements() { return sqlStatements; } @@ -188,6 +190,9 @@ protected SqlStatements sqlStatements() { @Inject Event storageEvent; + @Inject + Event outboxEvent; + private volatile boolean isReady = false; private volatile Instant isAliveLastCheck = Instant.MIN; private volatile boolean isAliveCached = false; @@ -514,15 +519,19 @@ public Pair createArtifact(Stri .modifiedBy(owner).artifactType(artifactType).labels(labels).build(); // The artifact was successfully created! Create the version as well, if one was included. + ImmutablePair pair; if (versionContent != null) { ArtifactVersionMetaDataDto vmdDto = createArtifactVersionRaw(handle, true, groupId, artifactId, version, versionMetaData, owner, createdOn, contentId, versionBranches); - return ImmutablePair.of(amdDto, vmdDto); + pair = ImmutablePair.of(amdDto, vmdDto); } else { - return ImmutablePair.left(amdDto); + pair = ImmutablePair.of(amdDto, null); } + + outboxEvent.fire(ArtifactCreatedEvent.of(amdDto)); + return pair; }); } catch (Exception ex) { if (sqlStatements.isPrimaryKeyViolation(ex)) {