Skip to content

Commit 478ede1

Browse files
committed
Implement "dryRun" feature by using the new Tx rollback capability of Handle
1 parent ebbbec2 commit 478ede1

18 files changed

+255
-79
lines changed

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/AbstractResource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ protected ArtifactVersionMetaDataDto createOrUpdateArtifact(String subject, Stri
9292
.contentType(contentType).references(parsedReferences).build();
9393

9494
res = storage.createArtifact(groupId, subject, artifactType, artifactMetaData, null,
95-
firstVersionContent, firstVersionMetaData, null).getValue();
95+
firstVersionContent, firstVersionMetaData, null, false).getValue();
9696
} else {
9797
TypedContent typedSchemaContent = TypedContent.create(schemaContent, contentType);
9898
rulesService.applyRules(groupId, subject, artifactType, typedSchemaContent,
9999
RuleApplicationType.UPDATE, artifactReferences, resolvedReferences);
100100
ContentWrapperDto versionContent = ContentWrapperDto.builder().content(schemaContent)
101101
.contentType(contentType).references(parsedReferences).build();
102102
res = storage.createArtifactVersion(groupId, subject, null, artifactType, versionContent,
103-
EditableVersionMetaDataDto.builder().build(), List.of());
103+
EditableVersionMetaDataDto.builder().build(), List.of(), false);
104104
}
105105
} catch (RuleViolationException ex) {
106106
if (ex.getRuleType() == RuleType.VALIDITY) {

app/src/main/java/io/apicurio/registry/limits/RegistryStorageLimitsEnforcer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ public int order() {
6060
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
6161
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
6262
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
63-
List<String> versionBranches) throws RegistryStorageException {
63+
List<String> versionBranches, boolean dryRun) throws RegistryStorageException {
6464
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> rval = withLimitsCheck(
6565
() -> limitsService.canCreateArtifact(artifactMetaData, versionContent, versionMetaData))
6666
.execute(() -> super.createArtifact(groupId, artifactId, artifactType, artifactMetaData,
67-
version, versionContent, versionMetaData, versionBranches));
67+
version, versionContent, versionMetaData, versionBranches, dryRun));
6868
limitsService.artifactCreated();
6969
return rval;
7070
}
7171

7272
@Override
7373
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
7474
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
75-
List<String> branches) throws RegistryStorageException {
75+
List<String> branches, boolean dryRun) throws RegistryStorageException {
7676
ArtifactVersionMetaDataDto dto = withLimitsCheck(
7777
() -> limitsService.canCreateArtifactVersion(groupId, artifactId, null, content.getContent()))
7878
.execute(() -> super.createArtifactVersion(groupId, artifactId, version, artifactType,
79-
content, metaData, branches));
79+
content, metaData, branches, dryRun));
8080
limitsService.artifactVersionCreated(groupId, artifactId);
8181
return dto;
8282
}

app/src/main/java/io/apicurio/registry/rest/v2/GroupsResourceImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ private ArtifactMetaData createArtifactWithRefs(String groupId, String xRegistry
10851085

10861086
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createResult = storage.createArtifact(
10871087
defaultGroupIdToNull(groupId), artifactId, artifactType, metaData, xRegistryVersion,
1088-
contentDto, versionMetaData, List.of());
1088+
contentDto, versionMetaData, List.of(), false);
10891089

10901090
return V2ApiUtil.dtoToMetaData(groupId, artifactId, artifactType, createResult.getRight());
10911091
} catch (ArtifactAlreadyExistsException ex) {
@@ -1210,7 +1210,7 @@ private VersionMetaData createArtifactVersionWithRefs(String groupId, String art
12101210
ContentWrapperDto contentDto = ContentWrapperDto.builder().content(content).contentType(ct)
12111211
.references(referencesAsDtos).build();
12121212
ArtifactVersionMetaDataDto vmdDto = storage.createArtifactVersion(defaultGroupIdToNull(groupId),
1213-
artifactId, xRegistryVersion, artifactType, contentDto, metaData, List.of());
1213+
artifactId, xRegistryVersion, artifactType, contentDto, metaData, List.of(), false);
12141214
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, artifactType,
12151215
vmdDto);
12161216
}
@@ -1345,7 +1345,7 @@ private ArtifactMetaData updateArtifactInternal(String groupId, String artifactI
13451345
ContentWrapperDto contentDto = ContentWrapperDto.builder().content(content).contentType(contentType)
13461346
.references(referencesAsDtos).build();
13471347
ArtifactVersionMetaDataDto dto = storage.createArtifactVersion(defaultGroupIdToNull(groupId),
1348-
artifactId, version, artifactType, contentDto, metaData, List.of());
1348+
artifactId, version, artifactType, contentDto, metaData, List.of(), false);
13491349

13501350
// Note: if the version was created, we need to update the artifact metadata as well, because
13511351
// those are the semantics of the v2 API. :(

app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java

+4-25
Original file line numberDiff line numberDiff line change
@@ -823,21 +823,10 @@ public CreateArtifactResponse createArtifact(String groupId, IfArtifactExists if
823823
firstVersionBranches = data.getFirstVersion().getBranches();
824824
}
825825

826-
// Don't actually do anything if "dryRun" is 'true'
827-
if (dryRun != null && dryRun) {
828-
return CreateArtifactResponse.builder()
829-
.artifact(ArtifactMetaData.builder().groupId(groupId).artifactId(artifactId)
830-
.createdOn(new Date()).owner(securityIdentity.getPrincipal().getName())
831-
.modifiedBy(securityIdentity.getPrincipal().getName()).modifiedOn(new Date())
832-
.name(artifactMetaData.getName())
833-
.description(artifactMetaData.getDescription())
834-
.labels(artifactMetaData.getLabels()).artifactType(artifactType).build())
835-
.build();
836-
}
837-
838826
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> storageResult = storage.createArtifact(
839827
new GroupId(groupId).getRawGroupIdWithNull(), artifactId, artifactType, artifactMetaData,
840-
firstVersion, firstVersionContent, firstVersionMetaData, firstVersionBranches);
828+
firstVersion, firstVersionContent, firstVersionMetaData, firstVersionBranches,
829+
dryRun != null && dryRun);
841830

842831
// Now return both the artifact metadata and (if available) the version metadata
843832
CreateArtifactResponse rval = CreateArtifactResponse.builder()
@@ -919,19 +908,9 @@ public VersionMetaData createArtifactVersion(String groupId, String artifactId,
919908
ContentWrapperDto contentDto = ContentWrapperDto.builder().contentType(ct).content(content)
920909
.references(referencesAsDtos).build();
921910

922-
// Don't actually do anything if "dryRun" is 'true'
923-
if (dryRun != null && dryRun) {
924-
return VersionMetaData.builder().groupId(groupId).artifactId(artifactId)
925-
.version(data.getVersion() == null ? "0" : data.getVersion()).createdOn(new Date())
926-
.owner(securityIdentity.getPrincipal().getName()).contentId(-1L)
927-
.name(metaDataDto.getName()).description(metaDataDto.getDescription())
928-
.labels(metaDataDto.getLabels()).state(VersionState.ENABLED).globalId(-1L)
929-
.artifactType(artifactType).build();
930-
}
931-
932911
ArtifactVersionMetaDataDto vmd = storage.createArtifactVersion(
933912
new GroupId(groupId).getRawGroupIdWithNull(), artifactId, data.getVersion(), artifactType,
934-
contentDto, metaDataDto, data.getBranches());
913+
contentDto, metaDataDto, data.getBranches(), dryRun != null && dryRun);
935914

936915
return V3ApiUtil.dtoToVersionMetaData(vmd);
937916
}
@@ -1197,7 +1176,7 @@ private CreateArtifactResponse updateArtifactInternal(String groupId, String art
11971176
ContentWrapperDto contentDto = ContentWrapperDto.builder().contentType(contentType).content(content)
11981177
.references(referencesAsDtos).build();
11991178
ArtifactVersionMetaDataDto vmdDto = storage.createArtifactVersion(groupId, artifactId, version,
1200-
artifactType, contentDto, metaData, branches);
1179+
artifactType, contentDto, metaData, branches, false);
12011180
VersionMetaData vmd = V3ApiUtil.dtoToVersionMetaData(vmdDto);
12021181

12031182
// Need to also return the artifact metadata

app/src/main/java/io/apicurio/registry/storage/RegistryStorage.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public interface RegistryStorage extends DynamicConfigStorage {
106106
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId, String artifactId,
107107
String artifactType, EditableArtifactMetaDataDto artifactMetaData, String version,
108108
ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
109-
List<String> versionBranches) throws ArtifactAlreadyExistsException, RegistryStorageException;
109+
List<String> versionBranches, boolean dryRun) throws ArtifactAlreadyExistsException, RegistryStorageException;
110110

111111
/**
112112
* Deletes an artifact by its group and unique id. Returns list of artifact versions.
@@ -178,10 +178,11 @@ ContentWrapperDto getContentByHash(String contentHash)
178178
* @param content
179179
* @param metaData
180180
* @param branches
181+
* @param dryRun
181182
*/
182183
ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
183184
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
184-
List<String> branches)
185+
List<String> branches, boolean dryRun)
185186
throws ArtifactNotFoundException, VersionAlreadyExistsException, RegistryStorageException;
186187

187188
/**

app/src/main/java/io/apicurio/registry/storage/decorator/ReadOnlyRegistryStorageDecorator.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public boolean isReadOnly() {
8686
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
8787
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
8888
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
89-
List<String> versionBranches) throws RegistryStorageException {
89+
List<String> versionBranches, boolean dryRun) throws RegistryStorageException {
9090
checkReadOnly();
9191
return delegate.createArtifact(groupId, artifactId, artifactType, artifactMetaData, version,
92-
versionContent, versionMetaData, versionBranches);
92+
versionContent, versionMetaData, versionBranches, dryRun);
9393
}
9494

9595
@Override
@@ -108,10 +108,10 @@ public void deleteArtifacts(String groupId) throws RegistryStorageException {
108108
@Override
109109
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
110110
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
111-
List<String> branches) throws RegistryStorageException {
111+
List<String> branches, boolean dryRun) throws RegistryStorageException {
112112
checkReadOnly();
113113
return delegate.createArtifactVersion(groupId, artifactId, version, artifactType, content, metaData,
114-
branches);
114+
branches, dryRun);
115115
}
116116

117117
@Override

app/src/main/java/io/apicurio/registry/storage/decorator/RegistryStorageDecoratorBase.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ protected RegistryStorageDecoratorBase() {
5252
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
5353
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
5454
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
55-
List<String> versionBranches) throws RegistryStorageException {
55+
List<String> versionBranches, boolean dryRun) throws RegistryStorageException {
5656
return delegate.createArtifact(groupId, artifactId, artifactType, artifactMetaData, version,
57-
versionContent, versionMetaData, versionBranches);
57+
versionContent, versionMetaData, versionBranches, dryRun);
5858
}
5959

6060
@Override
@@ -71,9 +71,9 @@ public void deleteArtifacts(String groupId) throws RegistryStorageException {
7171
@Override
7272
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
7373
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
74-
List<String> branches) throws RegistryStorageException {
74+
List<String> branches, boolean dryRun) throws RegistryStorageException {
7575
return delegate.createArtifactVersion(groupId, artifactId, version, artifactType, content, metaData,
76-
branches);
76+
branches, dryRun);
7777
}
7878

7979
@Override

app/src/main/java/io/apicurio/registry/storage/impl/gitops/AbstractReadOnlyRegistryStorage.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public boolean isReadOnly() {
5151
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
5252
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
5353
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
54-
List<String> versionBranches) throws RegistryStorageException {
54+
List<String> versionBranches, boolean dryRun) throws RegistryStorageException {
5555
readOnlyViolation();
5656
return null;
5757
}
5858

5959
@Override
6060
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
6161
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
62-
List<String> branches) throws RegistryStorageException {
62+
List<String> branches, boolean dryRun) throws RegistryStorageException {
6363
readOnlyViolation();
6464
return null;
6565
}

app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/KafkaSqlRegistryStorage.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,13 @@ public void deleteConfigProperty(String propertyName) {
375375
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
376376
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
377377
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
378-
List<String> versionBranches) throws RegistryStorageException {
378+
List<String> versionBranches, boolean dryRun) throws RegistryStorageException {
379379
String content = versionContent != null ? versionContent.getContent().content() : null;
380380
String contentType = versionContent != null ? versionContent.getContentType() : null;
381381
List<ArtifactReferenceDto> references = versionContent != null ? versionContent.getReferences()
382382
: null;
383-
var message = new CreateArtifact8Message(groupId, artifactId, artifactType, artifactMetaData, version,
384-
contentType, content, references, versionMetaData, versionBranches);
383+
var message = new CreateArtifact9Message(groupId, artifactId, artifactType, artifactMetaData, version,
384+
contentType, content, references, versionMetaData, versionBranches, dryRun);
385385
var uuid = ConcurrentUtil.get(submitter.submitMessage(message));
386386
return (Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto>) coordinator.waitForResponse(uuid);
387387
}
@@ -411,12 +411,12 @@ public void deleteArtifacts(String groupId) throws RegistryStorageException {
411411
@Override
412412
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
413413
String artifactType, ContentWrapperDto contentDto, EditableVersionMetaDataDto metaData,
414-
List<String> branches) throws RegistryStorageException {
414+
List<String> branches, boolean dryRun) throws RegistryStorageException {
415415
String content = contentDto != null ? contentDto.getContent().content() : null;
416416
String contentType = contentDto != null ? contentDto.getContentType() : null;
417417
List<ArtifactReferenceDto> references = contentDto != null ? contentDto.getReferences() : null;
418-
var message = new CreateArtifactVersion7Message(groupId, artifactId, version, artifactType,
419-
contentType, content, references, metaData, branches);
418+
var message = new CreateArtifactVersion8Message(groupId, artifactId, version, artifactType,
419+
contentType, content, references, metaData, branches, dryRun);
420420
var uuid = ConcurrentUtil.get(submitter.submitMessage(message));
421421
return (ArtifactVersionMetaDataDto) coordinator.waitForResponse(uuid);
422422
}

app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/messages/CreateArtifact8Message.java app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/messages/CreateArtifact9Message.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@Setter
2525
@EqualsAndHashCode(callSuper = false)
2626
@ToString
27-
public class CreateArtifact8Message extends AbstractMessage {
27+
public class CreateArtifact9Message extends AbstractMessage {
2828

2929
private String groupId;
3030
private String artifactId;
@@ -36,6 +36,7 @@ public class CreateArtifact8Message extends AbstractMessage {
3636
private List<ArtifactReferenceDto> references;
3737
private EditableVersionMetaDataDto versionMetaData;
3838
private List<String> versionBranches;
39+
private boolean dryRun;
3940

4041
/**
4142
* @see io.apicurio.registry.storage.impl.kafkasql.KafkaSqlMessage#dispatchTo(io.apicurio.registry.storage.RegistryStorage)
@@ -47,7 +48,7 @@ public Object dispatchTo(RegistryStorage storage) {
4748
.contentType(contentType).content(handle).references(references).build()
4849
: null;
4950
return storage.createArtifact(groupId, artifactId, artifactType, artifactMetaDataDto, version,
50-
versionContent, versionMetaData, versionBranches);
51+
versionContent, versionMetaData, versionBranches, dryRun);
5152
}
5253

5354
}

app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/messages/CreateArtifactVersion7Message.java app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/messages/CreateArtifactVersion8Message.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323
@Setter
2424
@EqualsAndHashCode(callSuper = false)
2525
@ToString
26-
public class CreateArtifactVersion7Message extends AbstractMessage {
26+
public class CreateArtifactVersion8Message extends AbstractMessage {
2727

28-
String groupId;
29-
String artifactId;
30-
String version;
31-
String artifactType;
28+
private String groupId;
29+
private String artifactId;
30+
private String version;
31+
private String artifactType;
3232
private String contentType;
3333
private String content;
3434
private List<ArtifactReferenceDto> references;
35-
EditableVersionMetaDataDto metaData;
36-
List<String> branches;
35+
private EditableVersionMetaDataDto metaData;
36+
private List<String> branches;
37+
boolean dryRun;
3738

3839
/**
3940
* @see io.apicurio.registry.storage.impl.kafkasql.KafkaSqlMessage#dispatchTo(io.apicurio.registry.storage.RegistryStorage)
@@ -45,7 +46,7 @@ public Object dispatchTo(RegistryStorage storage) {
4546
.content(handle).references(references).build()
4647
: null;
4748
return storage.createArtifactVersion(groupId, artifactId, version, artifactType, contentDto, metaData,
48-
branches);
49+
branches, dryRun);
4950
}
5051

5152
}

app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/messages/CreateGlobalRule2Message.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
@ToString
2222
public class CreateGlobalRule2Message extends AbstractMessage {
2323

24-
RuleType rule;
25-
RuleConfigurationDto config;
24+
private RuleType rule;
25+
private RuleConfigurationDto config;
2626

2727
/**
2828
* @see io.apicurio.registry.storage.impl.kafkasql.KafkaSqlMessage#dispatchTo(io.apicurio.registry.storage.RegistryStorage)

0 commit comments

Comments
 (0)