Skip to content

Commit 2321e0c

Browse files
committed
fix: improve kafkasql upgrade process, fix protobuf with references upgrade issue
1 parent 0aa2d7e commit 2321e0c

File tree

78 files changed

+3877
-1809
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3877
-1809
lines changed

app/src/main/java/io/apicurio/registry/ccompat/rest/v6/impl/SchemasResourceImpl.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
import io.apicurio.registry.storage.ArtifactNotFoundException;
3131
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
3232
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
33-
import io.apicurio.registry.storage.dto.ContentWrapperDto;
33+
import io.apicurio.registry.storage.dto.ContentAndReferencesDto;
3434
import io.apicurio.registry.storage.dto.StoredArtifactDto;
35+
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
3536
import io.apicurio.registry.types.ArtifactType;
3637
import io.apicurio.registry.util.ArtifactTypeUtil;
3738
import jakarta.interceptor.Interceptors;
@@ -61,16 +62,24 @@ public SchemaInfo getSchema(int id) {
6162
contentHandle = artifactVersion.getContent();
6263
references = artifactVersion.getReferences();
6364
} else {
64-
ContentWrapperDto contentWrapper = getStorage().getArtifactByContentId(id);
65+
ContentAndReferencesDto contentAndReferences = getStorage().getArtifactByContentId(id);
6566
contentHandle = getStorage().getArtifactByContentId(id).getContent();
66-
references = contentWrapper.getReferences();
67+
references = contentAndReferences.getReferences();
6768
List<ArtifactMetaDataDto> artifacts = getStorage().getArtifactVersionsByContentId(id);
6869
if (artifacts == null || artifacts.isEmpty()) {
6970
//the contentId points to an orphaned content
7071
throw new ArtifactNotFoundException("ContentId: " + id);
7172
}
7273
}
73-
return getConverter().convert(contentHandle, ArtifactTypeUtil.determineArtifactType(contentHandle, null, null, getStorage().resolveReferences(references), getFactory().getAllArtifactTypes()), references);
74+
return getConverter().convert(contentHandle,
75+
ArtifactTypeUtil.determineArtifactType(
76+
contentHandle,
77+
null,
78+
null,
79+
RegistryContentUtils.recursivelyResolveReferences(references, r -> getStorage().getContentByReference(r)),
80+
getFactory().getAllArtifactTypes()
81+
),
82+
references);
7483
}
7584

7685
@Override

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.apicurio.registry.storage.ArtifactNotFoundException;
3434
import io.apicurio.registry.storage.RuleNotFoundException;
3535
import io.apicurio.registry.storage.VersionNotFoundException;
36+
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
3637
import io.apicurio.registry.types.ArtifactState;
3738
import io.apicurio.registry.types.ArtifactType;
3839
import io.apicurio.registry.types.Current;
@@ -106,7 +107,7 @@ protected ArtifactMetaDataDto createOrUpdateArtifact(String subject, String sche
106107
ArtifactMetaDataDto res;
107108
final List<ArtifactReferenceDto> parsedReferences = parseReferences(references, groupId);
108109
final List<ArtifactReference> artifactReferences = parsedReferences.stream().map(dto -> ArtifactReference.builder().name(dto.getName()).groupId(dto.getGroupId()).artifactId(dto.getArtifactId()).version(dto.getVersion()).build()).collect(Collectors.toList());
109-
final Map<String, ContentHandle> resolvedReferences = storage.resolveReferences(parsedReferences);
110+
final Map<String, ContentHandle> resolvedReferences = RegistryContentUtils.recursivelyResolveReferences(parsedReferences, storage::getContentByReference);
110111
try {
111112
ContentHandle schemaContent;
112113
schemaContent = ContentHandle.create(schema);
@@ -147,7 +148,7 @@ protected ArtifactVersionMetaDataDto lookupSchema(String groupId, String subject
147148
amd = storage.getArtifactVersions(groupId, subject)
148149
.stream().filter(version -> {
149150
StoredArtifactDto artifactVersion = storage.getArtifactVersion(groupId, subject, version);
150-
Map<String, ContentHandle> artifactVersionReferences = storage.resolveReferences(artifactVersion.getReferences());
151+
Map<String, ContentHandle> artifactVersionReferences = RegistryContentUtils.recursivelyResolveReferences(artifactVersion.getReferences(), storage::getContentByReference);
151152
String dereferencedExistingContentSha = DigestUtils.sha256Hex(artifactTypeProvider.getContentDereferencer().dereference(artifactVersion.getContent(), artifactVersionReferences).content());
152153
return dereferencedExistingContentSha.equals(DigestUtils.sha256Hex(schema));
153154
})
@@ -182,7 +183,7 @@ protected Map<String, ContentHandle> resolveReferences(List<SchemaReference> ref
182183
return artifactReferenceDto;
183184
}).collect(Collectors.toList());
184185

185-
resolvedReferences = storage.resolveReferences(referencesAsDtos);
186+
resolvedReferences = RegistryContentUtils.recursivelyResolveReferences(referencesAsDtos, storage::getContentByReference);
186187

187188
if (references.size() > resolvedReferences.size()) {
188189
//There are unresolvable references, which is not allowed.

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
import io.apicurio.registry.content.ContentHandle;
2727
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
2828
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
29+
import io.apicurio.registry.storage.ArtifactNotFoundException;
2930
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
3031
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
31-
import io.apicurio.registry.storage.dto.ContentWrapperDto;
32+
import io.apicurio.registry.storage.dto.ContentAndReferencesDto;
3233
import io.apicurio.registry.storage.dto.StoredArtifactDto;
33-
import io.apicurio.registry.storage.ArtifactNotFoundException;
34+
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
3435
import io.apicurio.registry.types.ArtifactType;
3536
import io.apicurio.registry.util.ArtifactTypeUtil;
3637
import jakarta.interceptor.Interceptors;
@@ -59,16 +60,24 @@ public SchemaInfo getSchema(int id, String subject, String groupId) {
5960
contentHandle = artifactVersion.getContent();
6061
references = artifactVersion.getReferences();
6162
} else {
62-
ContentWrapperDto contentWrapper = storage.getArtifactByContentId(id);
63+
ContentAndReferencesDto contentAndReferences = storage.getArtifactByContentId(id);
6364
contentHandle = storage.getArtifactByContentId(id).getContent();
64-
references = contentWrapper.getReferences();
65+
references = contentAndReferences.getReferences();
6566
List<ArtifactMetaDataDto> artifacts = storage.getArtifactVersionsByContentId(id);
6667
if (artifacts == null || artifacts.isEmpty()) {
6768
//the contentId points to an orphaned content
6869
throw new ArtifactNotFoundException("ContentId: " + id);
6970
}
7071
}
71-
return converter.convert(contentHandle, ArtifactTypeUtil.determineArtifactType(contentHandle, null, null, storage.resolveReferences(references), factory.getAllArtifactTypes()), references);
72+
return converter.convert(contentHandle,
73+
ArtifactTypeUtil.determineArtifactType(
74+
contentHandle,
75+
null,
76+
null,
77+
RegistryContentUtils.recursivelyResolveReferences(references, storage::getContentByReference),
78+
factory.getAllArtifactTypes()
79+
),
80+
references);
7281
}
7382

7483
@Override

app/src/main/java/io/apicurio/registry/events/EventSourcedRegistryStorage.java

+6-76
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,17 @@
2020
import io.apicurio.registry.events.dto.ArtifactRuleChange;
2121
import io.apicurio.registry.events.dto.ArtifactStateChange;
2222
import io.apicurio.registry.events.dto.RegistryEventType;
23-
import io.apicurio.registry.storage.ArtifactAlreadyExistsException;
24-
import io.apicurio.registry.storage.ArtifactNotFoundException;
25-
import io.apicurio.registry.storage.ContentNotFoundException;
26-
import io.apicurio.registry.storage.GroupAlreadyExistsException;
27-
import io.apicurio.registry.storage.GroupNotFoundException;
28-
import io.apicurio.registry.storage.RegistryStorageException;
29-
import io.apicurio.registry.storage.RuleAlreadyExistsException;
30-
import io.apicurio.registry.storage.RuleNotFoundException;
31-
import io.apicurio.registry.storage.VersionNotFoundException;
23+
import io.apicurio.registry.storage.*;
3224
import io.apicurio.registry.storage.decorator.RegistryStorageDecorator;
33-
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
34-
import io.apicurio.registry.storage.dto.ArtifactOwnerDto;
35-
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
36-
import io.apicurio.registry.storage.dto.ContentWrapperDto;
37-
import io.apicurio.registry.storage.dto.EditableArtifactMetaDataDto;
38-
import io.apicurio.registry.storage.dto.GroupMetaDataDto;
39-
import io.apicurio.registry.storage.dto.GroupSearchResultsDto;
40-
import io.apicurio.registry.storage.dto.OrderBy;
41-
import io.apicurio.registry.storage.dto.OrderDirection;
42-
import io.apicurio.registry.storage.dto.RuleConfigurationDto;
43-
import io.apicurio.registry.storage.dto.SearchFilter;
44-
import io.apicurio.registry.storage.dto.StoredArtifactDto;
25+
import io.apicurio.registry.storage.dto.*;
4526
import io.apicurio.registry.types.ArtifactState;
4627
import io.apicurio.registry.types.RuleType;
28+
import jakarta.enterprise.context.ApplicationScoped;
29+
import jakarta.inject.Inject;
4730

4831
import java.util.HashMap;
4932
import java.util.List;
50-
import java.util.Map;
5133
import java.util.Optional;
52-
import java.util.Set;
53-
import jakarta.enterprise.context.ApplicationScoped;
54-
import jakarta.inject.Inject;
5534

5635
/**
5736
* @author Fabian Martinez
@@ -125,7 +104,7 @@ public ArtifactMetaDataDto createArtifact(String groupId, String artifactId,
125104
*/
126105
@Override
127106
public ArtifactMetaDataDto createArtifactWithMetadata(String groupId, String artifactId, String version,
128-
String artifactType, ContentHandle content, EditableArtifactMetaDataDto metaData, List<ArtifactReferenceDto> references) throws ArtifactAlreadyExistsException, RegistryStorageException {
107+
String artifactType, ContentHandle content, EditableArtifactMetaDataDto metaData, List<ArtifactReferenceDto> references) throws ArtifactAlreadyExistsException, RegistryStorageException {
129108
ArtifactMetaDataDto meta = delegate.createArtifactWithMetadata(groupId, artifactId, version, artifactType, content, metaData, references);
130109
ArtifactId data = new ArtifactId();
131110
data.setGroupId(groupId);
@@ -154,26 +133,6 @@ public void deleteArtifacts(String groupId) throws RegistryStorageException {
154133
fireEvent(RegistryEventType.ARTIFACTS_IN_GROUP_DELETED, groupId, data, null);
155134
}
156135

157-
@Override
158-
public StoredArtifactDto getArtifact(String groupId, String artifactId) throws ArtifactNotFoundException, RegistryStorageException {
159-
return delegate.getArtifact(groupId, artifactId);
160-
}
161-
162-
@Override
163-
public StoredArtifactDto getArtifact(String groupId, String artifactId, ArtifactRetrievalBehavior behavior) throws ArtifactNotFoundException, RegistryStorageException {
164-
return delegate.getArtifact(groupId, artifactId, behavior);
165-
}
166-
167-
@Override
168-
public ContentWrapperDto getArtifactByContentHash(String contentHash) throws ContentNotFoundException, RegistryStorageException {
169-
return delegate.getArtifactByContentHash(contentHash);
170-
}
171-
172-
@Override
173-
public ContentWrapperDto getArtifactByContentId(long contentId) throws ContentNotFoundException, RegistryStorageException {
174-
return delegate.getArtifactByContentId(contentId);
175-
}
176-
177136
@Override
178137
public ArtifactMetaDataDto updateArtifact(String groupId, String artifactId, String version, String artifactType, ContentHandle content, List<ArtifactReferenceDto> references)
179138
throws ArtifactNotFoundException, RegistryStorageException {
@@ -189,7 +148,7 @@ public ArtifactMetaDataDto updateArtifact(String groupId, String artifactId, Str
189148

190149
@Override
191150
public ArtifactMetaDataDto updateArtifactWithMetadata(String groupId, String artifactId, String version, String artifactType, ContentHandle content,
192-
EditableArtifactMetaDataDto metaData, List<ArtifactReferenceDto> references) throws ArtifactNotFoundException, RegistryStorageException {
151+
EditableArtifactMetaDataDto metaData, List<ArtifactReferenceDto> references) throws ArtifactNotFoundException, RegistryStorageException {
193152
ArtifactMetaDataDto meta = delegate.updateArtifactWithMetadata(groupId, artifactId, version, artifactType, content, metaData, references);
194153
ArtifactId data = new ArtifactId();
195154
data.setGroupId(groupId);
@@ -212,11 +171,6 @@ public void updateArtifactOwner(String groupId, String artifactId, ArtifactOwner
212171
//TODO consider a change ownership event
213172
}
214173

215-
@Override
216-
public List<RuleType> getArtifactRules(String groupId, String artifactId) throws ArtifactNotFoundException, RegistryStorageException {
217-
return delegate.getArtifactRules(groupId, artifactId);
218-
}
219-
220174
/**
221175
* @see io.apicurio.registry.storage.RegistryStorage#createArtifactRule(java.lang.String, java.lang.String, io.apicurio.registry.types.RuleType, io.apicurio.registry.storage.dto.RuleConfigurationDto)
222176
*/
@@ -333,28 +287,4 @@ public void deleteGroup(String groupId) throws GroupNotFoundException, RegistryS
333287
data.setGroupId(groupId);
334288
fireEvent(RegistryEventType.GROUP_DELETED, groupId, data, null);
335289
}
336-
337-
/**
338-
* @see io.apicurio.registry.storage.RegistryStorage#resolveReferences(List)
339-
*/
340-
@Override
341-
public Map<String, ContentHandle> resolveReferences(List<ArtifactReferenceDto> references) {
342-
return delegate.resolveReferences(references);
343-
}
344-
345-
/**
346-
* @see io.apicurio.registry.storage.RegistryStorage#isArtifactExists(String, String)
347-
*/
348-
@Override
349-
public boolean isArtifactExists(String groupId, String artifactId) throws RegistryStorageException {
350-
return delegate.isArtifactExists(groupId, artifactId);
351-
}
352-
353-
/**
354-
* @see io.apicurio.registry.storage.RegistryStorage#searchGroups(Set, OrderBy, OrderDirection, Integer, Integer)
355-
*/
356-
@Override
357-
public GroupSearchResultsDto searchGroups(Set<SearchFilter> filters, OrderBy orderBy, OrderDirection orderDirection, Integer offset, Integer limit) {
358-
return delegate.searchGroups(filters, orderBy, orderDirection, offset, limit);
359-
}
360290
}

0 commit comments

Comments
 (0)