Skip to content

Commit

Permalink
Fire artifact create event inside the db transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Oct 1, 2024
1 parent 9f6e6eb commit 826fef7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,12 +125,6 @@ public class GroupsResourceImpl extends AbstractResourceImpl implements GroupsRe
@Inject
SecurityIdentity securityIdentity;

@Inject
CommonResourceOperations common;

@Inject
Event<OutboxEvent> storageEvent;

public enum RegistryHashAlgorithm {
SHA256, MD5
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ public abstract class AbstractSqlRegistryStorage implements RegistryStorage {
@Inject
SemVerConfigProperties semVerConfigProps;

@Inject

protected SqlStatements sqlStatements() {
return sqlStatements;
}
Expand All @@ -188,6 +190,9 @@ protected SqlStatements sqlStatements() {
@Inject
Event<StorageEvent> storageEvent;

@Inject
Event<OutboxEvent> outboxEvent;

private volatile boolean isReady = false;
private volatile Instant isAliveLastCheck = Instant.MIN;
private volatile boolean isAliveCached = false;
Expand Down Expand Up @@ -514,15 +519,19 @@ public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(Stri
.modifiedBy(owner).artifactType(artifactType).labels(labels).build();

// The artifact was successfully created! Create the version as well, if one was included.
ImmutablePair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> 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)) {
Expand Down

0 comments on commit 826fef7

Please sign in to comment.