Skip to content

Commit 89a4f75

Browse files
authored
Fix a bug with Delete All Artifact Rules (kafkasql storage only) (#4282)
* Add test for deleting all artifact rules. Should fail for kafkasql right now... * Fixed deletion of global and artifact rules in kafkasql storage. * Fix a bug in the artifact rules value class.
1 parent 29dc521 commit 89a4f75

File tree

12 files changed

+411
-100
lines changed

12 files changed

+411
-100
lines changed

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

+4-19
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,8 @@ public void deleteArtifactRules(String groupId, String artifactId) {
444444
throw new ArtifactNotFoundException(groupId, artifactId);
445445
}
446446

447-
submitter.submitArtifactRule(groupId, artifactId, RuleType.COMPATIBILITY, ActionType.DELETE);
448-
449-
UUID reqId = ConcurrentUtil.get(submitter.submitArtifactRule(groupId, artifactId, RuleType.VALIDITY, ActionType.DELETE));
450-
try {
451-
coordinator.waitForResponse(reqId);
452-
} catch (RuleNotFoundException e) {
453-
// Eat this exception - we don't care if the rule didn't exist.
454-
}
447+
UUID reqId = ConcurrentUtil.get(submitter.submitArtifactRules(groupId, artifactId, ActionType.DELETE));
448+
coordinator.waitForResponse(reqId);
455449
}
456450

457451

@@ -533,17 +527,8 @@ public void createGlobalRule(RuleType rule, RuleConfigurationDto config) {
533527

534528
@Override
535529
public void deleteGlobalRules() {
536-
// TODO This should use "DELETE FROM" instead of being rule specific
537-
538-
getGlobalRules().stream()
539-
.map(r -> ConcurrentUtil.get(submitter.submitGlobalRule(r, ActionType.DELETE)))
540-
.forEach(reqId -> {
541-
try {
542-
coordinator.waitForResponse(reqId);
543-
} catch (RuleNotFoundException e) {
544-
// Eat this exception - we don't care if the rule didn't exist.
545-
}
546-
});
530+
UUID reqId = ConcurrentUtil.get(submitter.submitGlobalRules(ActionType.DELETE));
531+
coordinator.waitForResponse(reqId);
547532
}
548533

549534

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

+42-22
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public CompletableFuture<UUID> send(MessageKey key, MessageValue value) {
7272
* Content
7373
* ****************************************************************************************** */
7474
public CompletableFuture<UUID> submitContent(long contentId, String contentHash, ActionType action, String canonicalHash, ContentHandle content, String serializedReferences) {
75-
ContentKey key = ContentKey.create( contentId, contentHash);
75+
ContentKey key = ContentKey.create(contentId, contentHash);
7676
ContentValue value = ContentValue.create(action, canonicalHash, content, serializedReferences);
7777
return send(key, value);
7878
}
@@ -87,7 +87,7 @@ public CompletableFuture<UUID> submitGroup(ActionType action, GroupMetaDataDto m
8787
return send(key, value);
8888
}
8989
public CompletableFuture<UUID> submitGroup(String groupId, ActionType action, boolean onlyArtifacts) {
90-
GroupKey key = GroupKey.create( groupId);
90+
GroupKey key = GroupKey.create(groupId);
9191
GroupValue value = GroupValue.create(action, onlyArtifacts);
9292
return send(key, value);
9393
}
@@ -99,19 +99,19 @@ public CompletableFuture<UUID> submitGroup(String groupId, ActionType action, bo
9999
public CompletableFuture<UUID> submitArtifact(String groupId, String artifactId, String version, ActionType action,
100100
Long globalId, String artifactType, String contentHash, String createdBy, Date createdOn,
101101
EditableArtifactMetaDataDto metaData, Integer versionOrder, ArtifactState state, Long contentId) {
102-
ArtifactKey key = ArtifactKey.create( groupId, artifactId);
102+
ArtifactKey key = ArtifactKey.create(groupId, artifactId);
103103
ArtifactValue value = ArtifactValue.create(action, globalId, version, artifactType, contentHash, createdBy, createdOn, metaData,
104104
versionOrder, state, contentId);
105105
return send(key, value);
106106
}
107107
public CompletableFuture<UUID> submitArtifact(String groupId, String artifactId, String version, ActionType action,
108108
Long globalId, String artifactType, String contentHash, String createdBy, Date createdOn,
109109
EditableArtifactMetaDataDto metaData) {
110-
return submitArtifact( groupId, artifactId, version, action, globalId, artifactType, contentHash, createdBy, createdOn,
110+
return submitArtifact(groupId, artifactId, version, action, globalId, artifactType, contentHash, createdBy, createdOn,
111111
metaData, null, null, null);
112112
}
113113
public CompletableFuture<UUID> submitArtifact(String groupId, String artifactId, ActionType action) {
114-
return this.submitArtifact( groupId, artifactId, null, action, null, null, null, null, null, null);
114+
return this.submitArtifact(groupId, artifactId, null, action, null, null, null, null, null, null);
115115
}
116116

117117

@@ -120,20 +120,20 @@ public CompletableFuture<UUID> submitArtifact(String groupId, String artifactId,
120120
* ****************************************************************************************** */
121121
public CompletableFuture<UUID> submitArtifactVersion(String groupId, String artifactId, String version, ActionType action, ArtifactState state,
122122
EditableArtifactMetaDataDto metaData) {
123-
ArtifactVersionKey key = ArtifactVersionKey.create( groupId, artifactId, version);
123+
ArtifactVersionKey key = ArtifactVersionKey.create(groupId, artifactId, version);
124124
ArtifactVersionValue value = ArtifactVersionValue.create(action, state, metaData);
125125
return send(key, value);
126126
}
127127
public CompletableFuture<UUID> submitVersion(String groupId, String artifactId, String version, ActionType action) {
128-
return submitArtifactVersion( groupId, artifactId, version, action, null, null);
128+
return submitArtifactVersion(groupId, artifactId, version, action, null, null);
129129
}
130130

131131

132132
/* ******************************************************************************************
133133
* Artifact Owner
134134
* ****************************************************************************************** */
135135
public CompletableFuture<UUID> submitArtifactOwner(String groupId, String artifactId, ActionType action, String owner) {
136-
ArtifactOwnerKey key = ArtifactOwnerKey.create( groupId, artifactId);
136+
ArtifactOwnerKey key = ArtifactOwnerKey.create(groupId, artifactId);
137137
ArtifactOwnerValue value = ArtifactOwnerValue.create(action, owner);
138138
return send(key, value);
139139
}
@@ -144,12 +144,22 @@ public CompletableFuture<UUID> submitArtifactOwner(String groupId, String artifa
144144
* ****************************************************************************************** */
145145
public CompletableFuture<UUID> submitArtifactRule(String groupId, String artifactId, RuleType rule, ActionType action,
146146
RuleConfigurationDto config) {
147-
ArtifactRuleKey key = ArtifactRuleKey.create( groupId, artifactId, rule);
147+
ArtifactRuleKey key = ArtifactRuleKey.create(groupId, artifactId, rule);
148148
ArtifactRuleValue value = ArtifactRuleValue.create(action, config);
149149
return send(key, value);
150150
}
151151
public CompletableFuture<UUID> submitArtifactRule(String groupId, String artifactId, RuleType rule, ActionType action) {
152-
return submitArtifactRule( groupId, artifactId, rule, action, null);
152+
return submitArtifactRule(groupId, artifactId, rule, action, null);
153+
}
154+
155+
156+
/* ******************************************************************************************
157+
* Artifact Rules
158+
* ****************************************************************************************** */
159+
public CompletableFuture<UUID> submitArtifactRules(String groupId, String artifactId, ActionType action) {
160+
ArtifactRulesKey key = ArtifactRulesKey.create(groupId, artifactId);
161+
ArtifactRulesValue value = ArtifactRulesValue.create(action);
162+
return send(key, value);
153163
}
154164

155165

@@ -158,21 +168,21 @@ public CompletableFuture<UUID> submitArtifactRule(String groupId, String artifac
158168
* ****************************************************************************************** */
159169
public CompletableFuture<UUID> submitComment(String groupId, String artifactId, String version,
160170
String commentId, ActionType action, long globalId, String createdBy, Date createdOn, String value) {
161-
CommentKey key = CommentKey.create( groupId, artifactId, version, commentId);
171+
CommentKey key = CommentKey.create(groupId, artifactId, version, commentId);
162172
CommentValue cv = CommentValue.create(action, globalId, createdBy, createdOn, value);
163173
return send(key, cv);
164174
}
165175
public CompletableFuture<UUID> submitComment(String groupId, String artifactId, String version,
166176
String commentId, ActionType action, String createdBy, Date createdOn, String value) {
167-
return submitComment( groupId, artifactId, version, commentId, action, -1, createdBy, createdOn, value);
177+
return submitComment(groupId, artifactId, version, commentId, action, -1, createdBy, createdOn, value);
168178
}
169179
public CompletableFuture<UUID> submitComment(String groupId, String artifactId, String version,
170180
String commentId, ActionType action) {
171-
return submitComment( groupId, artifactId, version, commentId, action, null, null, null);
181+
return submitComment(groupId, artifactId, version, commentId, action, null, null, null);
172182
}
173183
public CompletableFuture<UUID> submitComment(String commentId, ActionType action, long globalId,
174184
String createdBy, Date createdOn, String value) {
175-
return submitComment( "<import-comments>", "_", "_", commentId, action, globalId, createdBy, createdOn, value);
185+
return submitComment("<import-comments>", "_", "_", commentId, action, globalId, createdBy, createdOn, value);
176186
}
177187

178188

@@ -185,20 +195,30 @@ public CompletableFuture<UUID> submitGlobalRule(RuleType rule, ActionType action
185195
return send(key, value);
186196
}
187197
public CompletableFuture<UUID> submitGlobalRule(RuleType rule, ActionType action) {
188-
return submitGlobalRule( rule, action, null);
198+
return submitGlobalRule(rule, action, null);
199+
}
200+
201+
202+
/* ******************************************************************************************
203+
* Global Rules
204+
* ****************************************************************************************** */
205+
public CompletableFuture<UUID> submitGlobalRules(ActionType action) {
206+
GlobalRulesKey key = GlobalRulesKey.create();
207+
GlobalRulesValue value = GlobalRulesValue.create(action);
208+
return send(key, value);
189209
}
190210

191211

192212
/* ******************************************************************************************
193213
* Role Mappings
194214
* ****************************************************************************************** */
195215
public CompletableFuture<UUID> submitRoleMapping(String principalId, ActionType action, String role, String principalName) {
196-
RoleMappingKey key = RoleMappingKey.create( principalId);
216+
RoleMappingKey key = RoleMappingKey.create(principalId);
197217
RoleMappingValue value = RoleMappingValue.create(action, role, principalName);
198218
return send(key, value);
199219
}
200220
public CompletableFuture<UUID> submitRoleMapping(String principalId, ActionType action) {
201-
return submitRoleMapping( principalId, action, null, null);
221+
return submitRoleMapping(principalId, action, null, null);
202222
}
203223

204224

@@ -237,12 +257,12 @@ public CompletableFuture<UUID> submitCommentId(ActionType action) {
237257
* ****************************************************************************************** */
238258

239259
public CompletableFuture<UUID> submitDownload(String downloadId, ActionType action, DownloadContextDto context) {
240-
DownloadKey key = DownloadKey.create( downloadId);
260+
DownloadKey key = DownloadKey.create(downloadId);
241261
DownloadValue value = DownloadValue.create(action, context);
242262
return send(key, value);
243263
}
244264
public CompletableFuture<UUID> submitDownload(String downloadId, ActionType action) {
245-
return submitDownload( downloadId, action, null);
265+
return submitDownload(downloadId, action, null);
246266
}
247267

248268

@@ -251,12 +271,12 @@ public CompletableFuture<UUID> submitDownload(String downloadId, ActionType acti
251271
* ****************************************************************************************** */
252272

253273
public CompletableFuture<UUID> submitConfigProperty(String propertyName, ActionType action, String propertyValue) {
254-
ConfigPropertyKey key = ConfigPropertyKey.create( propertyName);
274+
ConfigPropertyKey key = ConfigPropertyKey.create(propertyName);
255275
ConfigPropertyValue value = ConfigPropertyValue.create(action, propertyValue);
256276
return send(key, value);
257277
}
258278
public CompletableFuture<UUID> submitConfigProperty(String propertyName, ActionType action) {
259-
return submitConfigProperty( propertyName, action, null);
279+
return submitConfigProperty(propertyName, action, null);
260280
}
261281

262282

@@ -300,7 +320,7 @@ public CompletableFuture<UUID> submitGlobalAction(ActionType action) {
300320
* Tombstones
301321
* ****************************************************************************************** */
302322
public void submitArtifactVersionTombstone(String groupId, String artifactId, String version) {
303-
ArtifactVersionKey key = ArtifactVersionKey.create( groupId, artifactId, version);
323+
ArtifactVersionKey key = ArtifactVersionKey.create(groupId, artifactId, version);
304324
send(key, null);
305325
}
306326
public void submitArtifactRuleTombstone(String groupId, String artifactId, RuleType rule) {

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

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public enum MessageType {
2323
CommentId(15),
2424
Comment(16),
2525
ArtifactBranch(17),
26+
GlobalRules(18),
27+
ArtifactRules(19),
2628
;
2729

2830
private final byte ord;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package io.apicurio.registry.storage.impl.kafkasql.keys;
2+
3+
import io.apicurio.registry.storage.impl.kafkasql.MessageType;
4+
import io.quarkus.runtime.annotations.RegisterForReflection;
5+
6+
@RegisterForReflection
7+
public class ArtifactRulesKey implements MessageKey {
8+
9+
private String groupId;
10+
private String artifactId;
11+
12+
/**
13+
* Creator method.
14+
* @param groupId
15+
* @param artifactId
16+
* @param ruleType
17+
*/
18+
public static final ArtifactRulesKey create(String groupId, String artifactId) {
19+
ArtifactRulesKey key = new ArtifactRulesKey();
20+
key.setGroupId(groupId);
21+
key.setArtifactId(artifactId);
22+
return key;
23+
}
24+
25+
/**
26+
* @see MessageKey#getType()
27+
*/
28+
@Override
29+
public MessageType getType() {
30+
return MessageType.ArtifactRules;
31+
}
32+
33+
/**
34+
* @see MessageKey#getPartitionKey()
35+
*/
36+
@Override
37+
public String getPartitionKey() {
38+
return groupId + "/" + artifactId;
39+
}
40+
41+
/**
42+
* @return the groupId
43+
*/
44+
public String getGroupId() {
45+
return groupId;
46+
}
47+
48+
/**
49+
* @param groupId the groupId to set
50+
*/
51+
public void setGroupId(String groupId) {
52+
this.groupId = groupId;
53+
}
54+
55+
/**
56+
* @return the artifactId
57+
*/
58+
public String getArtifactId() {
59+
return artifactId;
60+
}
61+
62+
/**
63+
* @param artifactId the artifactId to set
64+
*/
65+
public void setArtifactId(String artifactId) {
66+
this.artifactId = artifactId;
67+
}
68+
69+
/**
70+
* @see Object#toString()
71+
*/
72+
@Override
73+
public String toString() {
74+
return "ArtifactRuleKey [groupId=" + groupId + ", artifactId=" + artifactId
75+
+ "]";
76+
}
77+
78+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@RegisterForReflection
88
public class GlobalRuleKey implements MessageKey {
99

10-
private static final String GLOBAL_RULE_PARTITION_KEY = "__apicurio_registry_global_rule__";
10+
static final String GLOBAL_RULE_PARTITION_KEY = "__apicurio_registry_global_rule__";
1111

1212
private RuleType ruleType;
1313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.apicurio.registry.storage.impl.kafkasql.keys;
2+
3+
import io.apicurio.registry.storage.impl.kafkasql.MessageType;
4+
import io.quarkus.runtime.annotations.RegisterForReflection;
5+
6+
@RegisterForReflection
7+
public class GlobalRulesKey implements MessageKey {
8+
9+
/**
10+
* Creator method.
11+
* @param ruleType
12+
*/
13+
public static final GlobalRulesKey create() {
14+
return new GlobalRulesKey();
15+
}
16+
17+
/**
18+
* @see MessageKey#getType()
19+
*/
20+
@Override
21+
public MessageType getType() {
22+
return MessageType.GlobalRules;
23+
}
24+
25+
/**
26+
* @see MessageKey#getPartitionKey()
27+
*/
28+
@Override
29+
public String getPartitionKey() {
30+
return GlobalRuleKey.GLOBAL_RULE_PARTITION_KEY;
31+
}
32+
33+
/**
34+
* @see io.apicurio.registry.storage.impl.kafkasql.keys.AbstractMessageKey#toString()
35+
*/
36+
@Override
37+
public String toString() {
38+
return getClass().getSimpleName();
39+
}
40+
41+
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public class MessageTypeToKeyClass {
6767
case ArtifactBranch:
6868
index.put(type, ArtifactBranchKey.class);
6969
break;
70+
case ArtifactRules:
71+
index.put(type, ArtifactRulesKey.class);
72+
break;
73+
case GlobalRules:
74+
index.put(type, GlobalRulesKey.class);
75+
break;
7076
default:
7177
throw new RuntimeAssertionFailedException("[MessageTypeToKeyClass] Type not mapped: " + type);
7278
}

0 commit comments

Comments
 (0)