Skip to content

Commit d9bcebb

Browse files
authored
Backport ccompat refactor (#4250)
* Backport integration tests changes * Add required test changes for backporting ccompat refactor * Add storage changes for backporting the ccompat refactor * Backport rest operations of ccompat refactor * Fix some merging missed changes * Fix ccompat api and ibm tests
1 parent a706462 commit d9bcebb

File tree

76 files changed

+4734
-1017
lines changed

Some content is hidden

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

76 files changed

+4734
-1017
lines changed

app/pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@
488488
<import>${project.basedir}/src/test/resources/io/apicurio/registry/serde/AvroSchemaD.avsc</import>
489489
<import>${project.basedir}/src/test/resources/io/apicurio/registry/serde/AvroSchemaC.avsc</import>
490490
<import>${project.basedir}/src/test/resources/io/apicurio/registry/serde/AvroSchemaB.avsc</import>
491+
<import>${project.basedir}/src/test/resources/io/apicurio/registry/ccompat/rest/subrecord.avsc</import>
492+
<import>${project.basedir}/src/test/resources/io/apicurio/registry/ccompat/rest/record.avsc</import>
491493
</imports>
492494
<sourceDirectory>${project.basedir}/src/test/resources/io/apicurio/registry/serde/</sourceDirectory>
493495
<outputDirectory>${project.basedir}/target/generated-test-sources</outputDirectory>

app/src/main/java/io/apicurio/registry/ccompat/rest/error/ConflictException.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ public class ConflictException extends RegistryException {
2626

2727
private static final long serialVersionUID = 5511072429790259605L;
2828

29-
public ConflictException(String message) {
30-
super(message);
31-
}
3229

33-
public ConflictException(String message, Throwable cause) {
34-
super(message, cause);
30+
public ConflictException(Throwable cause) {
31+
super(cause);
3532
}
3633
}

app/src/main/java/io/apicurio/registry/ccompat/rest/error/ErrorCode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
public enum ErrorCode {
2020

21-
SUBJECT_NOT_FOUND(40401), VERSION_NOT_FOUND(40402), SCHEMA_NOT_FOUND(40403), INVALID_SCHEMA(42201), INVALID_VERSION(42202), INVALID_COMPATIBILITY_LEVEL(42203), SERVER_ERROR(50001), OPERATION_TIMEOUT(50002), FORWARDING_ERROR(50003);
21+
SUBJECT_NOT_FOUND(40401), VERSION_NOT_FOUND(40402), SCHEMA_NOT_FOUND(40403), SUBJECT_SOFT_DELETED(40404), SUBJECT_NOT_SOFT_DELETED(40405), SCHEMA_VERSION_SOFT_DELETED(40406), SCHEMA_VERSION_NOT_SOFT_DELETED(40407), SUBJECT_COMPATIBILITY_NOT_CONFIGURED(40408), INVALID_SCHEMA(42201), INVALID_VERSION(42202), INVALID_COMPATIBILITY_LEVEL(42203), OPERATION_NOT_PERMITTED(42205), REFERENCE_EXISTS(42206), INVALID_SUBJECT(42208), SERVER_ERROR(50001), OPERATION_TIMEOUT(50002), FORWARDING_ERROR(50003);
2222

2323
private final int value;
2424

app/src/main/java/io/apicurio/registry/ccompat/rest/error/OperationNotSupportedException.java

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.apicurio.registry.ccompat.rest.error;
2+
3+
import io.apicurio.registry.types.RegistryException;
4+
5+
public class ReferenceExistsException extends RegistryException {
6+
7+
public ReferenceExistsException(String message) {
8+
super(message);
9+
}
10+
11+
public ReferenceExistsException(String message, Throwable cause) {
12+
super(message, cause);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.apicurio.registry.ccompat.rest.error;
2+
3+
import io.apicurio.registry.types.RegistryException;
4+
5+
public class SchemaNotFoundException extends RegistryException {
6+
public SchemaNotFoundException(String message) {
7+
super(message);
8+
}
9+
10+
public SchemaNotFoundException(String message, Throwable cause) {
11+
super(message, cause);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.apicurio.registry.ccompat.rest.error;
2+
3+
import io.apicurio.registry.types.RegistryException;
4+
5+
public class SchemaNotSoftDeletedException extends RegistryException {
6+
7+
public SchemaNotSoftDeletedException(String message) {
8+
super(message);
9+
}
10+
11+
public SchemaNotSoftDeletedException(String message, Throwable cause) {
12+
super(message, cause);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.apicurio.registry.ccompat.rest.error;
2+
3+
import io.apicurio.registry.types.RegistryException;
4+
5+
public class SchemaSoftDeletedException extends RegistryException {
6+
7+
public SchemaSoftDeletedException(String message) {
8+
super(message);
9+
}
10+
11+
public SchemaSoftDeletedException(String message, Throwable cause) {
12+
super(message, cause);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.apicurio.registry.ccompat.rest.error;
2+
3+
import io.apicurio.registry.types.RegistryException;
4+
5+
public class SubjectNotSoftDeletedException extends RegistryException {
6+
7+
public SubjectNotSoftDeletedException(String message) {
8+
super(message);
9+
}
10+
11+
public SubjectNotSoftDeletedException(String message, Throwable cause) {
12+
super(message, cause);
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.apicurio.registry.ccompat.rest.error;
2+
3+
import io.apicurio.registry.types.RegistryException;
4+
5+
public class SubjectSoftDeletedException extends RegistryException {
6+
public SubjectSoftDeletedException(String message) {
7+
super(message);
8+
}
9+
10+
public SubjectSoftDeletedException(String message, Throwable cause) {
11+
super(message, cause);
12+
}
13+
14+
}

app/src/main/java/io/apicurio/registry/ccompat/rest/error/UnprocessableEntityException.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public class UnprocessableEntityException extends RegistryException {
2828

2929
private static final long serialVersionUID = 1791019542026597523L;
3030

31+
3132
public UnprocessableEntityException(String message) {
3233
super(message);
3334
}
3435

35-
public UnprocessableEntityException(String message, Throwable cause) {
36-
super(message, cause);
36+
37+
public UnprocessableEntityException(Throwable cause) {
38+
super(cause);
3739
}
3840
}

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

+23-4
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@
1616

1717
package io.apicurio.registry.ccompat.rest.v6.impl;
1818

19+
import io.apicurio.common.apps.logging.Logged;
1920
import io.apicurio.registry.auth.Authorized;
2021
import io.apicurio.registry.auth.AuthorizedLevel;
2122
import io.apicurio.registry.auth.AuthorizedStyle;
2223
import io.apicurio.registry.ccompat.dto.CompatibilityCheckResponse;
2324
import io.apicurio.registry.ccompat.dto.SchemaContent;
25+
import io.apicurio.registry.ccompat.rest.error.UnprocessableEntityException;
2426
import io.apicurio.registry.ccompat.rest.v6.CompatibilityResource;
25-
import io.apicurio.common.apps.logging.Logged;
27+
import io.apicurio.registry.ccompat.rest.v7.impl.AbstractResource;
28+
import io.apicurio.registry.content.ContentHandle;
2629
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
2730
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
28-
31+
import io.apicurio.registry.rules.RuleViolationException;
32+
import io.apicurio.registry.rules.UnprocessableSchemaException;
33+
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
2934
import jakarta.enterprise.context.ApplicationScoped;
3035
import jakarta.interceptor.Interceptors;
3136

37+
import java.util.Collections;
38+
import java.util.List;
39+
3240
/**
3341
* @author Ales Justin
3442
* @author Jakub Senko <em>m@jsenko.net</em>
@@ -40,12 +48,23 @@
4048
public class CompatibilityResourceImpl extends AbstractResource implements CompatibilityResource {
4149

4250
@Override
43-
@Authorized(style=AuthorizedStyle.ArtifactOnly, level=AuthorizedLevel.Write)
51+
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
4452
public CompatibilityCheckResponse testCompatibilityBySubjectName(
4553
String subject,
4654
String versionString,
4755
SchemaContent request) throws Exception {
4856

49-
return facade.testCompatibilityByVersion(subject, versionString, request, false);
57+
try {
58+
final List<String> versions = getStorage().getArtifactVersions(null, subject);
59+
for (String version : versions) {
60+
final ArtifactVersionMetaDataDto artifactVersionMetaData = getStorage().getArtifactVersionMetaData(null, subject, version);
61+
getRulesService().applyRules(null, subject, version, artifactVersionMetaData.getType(), ContentHandle.create(request.getSchema()), Collections.emptyList(), Collections.emptyMap());
62+
}
63+
return CompatibilityCheckResponse.IS_COMPATIBLE;
64+
} catch (RuleViolationException ex) {
65+
return CompatibilityCheckResponse.IS_NOT_COMPATIBLE;
66+
} catch (UnprocessableSchemaException ex) {
67+
throw new UnprocessableEntityException(ex.getMessage());
68+
}
5069
}
5170
}

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

+25-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.apicurio.common.apps.logging.Logged;
2626
import io.apicurio.common.apps.logging.audit.Audited;
2727
import io.apicurio.common.apps.logging.audit.AuditingConstants;
28+
import io.apicurio.registry.ccompat.rest.v7.impl.AbstractResource;
2829
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
2930
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
3031
import io.apicurio.registry.rules.compatibility.CompatibilityLevel;
@@ -84,8 +85,7 @@ private void updateCompatibilityLevel(CompatibilityLevelDto.Level level,
8485
@Override
8586
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Admin)
8687
public CompatibilityLevelParamDto getGlobalCompatibilityLevel() {
87-
return getCompatibilityLevel(() ->
88-
facade.getGlobalRule(RuleType.COMPATIBILITY).getConfiguration());
88+
return getCompatibilityLevel(() -> getStorage().getGlobalRule(RuleType.COMPATIBILITY).getConfiguration());
8989
}
9090

9191

@@ -94,10 +94,15 @@ public CompatibilityLevelParamDto getGlobalCompatibilityLevel() {
9494
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Admin)
9595
public CompatibilityLevelDto updateGlobalCompatibilityLevel(
9696
CompatibilityLevelDto request) {
97-
9897
updateCompatibilityLevel(request.getCompatibility(),
99-
dto -> facade.createOrUpdateGlobalRule(RuleType.COMPATIBILITY, dto),
100-
() -> facade.deleteGlobalRule(RuleType.COMPATIBILITY));
98+
dto -> {
99+
if (!doesGlobalRuleExist(RuleType.COMPATIBILITY)) {
100+
getStorage().createGlobalRule(RuleType.COMPATIBILITY, dto);
101+
} else {
102+
getStorage().updateGlobalRule(RuleType.COMPATIBILITY, dto);
103+
}
104+
},
105+
() -> getStorage().deleteGlobalRule(RuleType.COMPATIBILITY));
101106
return request;
102107
}
103108

@@ -109,15 +114,26 @@ public CompatibilityLevelDto updateSubjectCompatibilityLevel(
109114
String subject,
110115
CompatibilityLevelDto request) {
111116
updateCompatibilityLevel(request.getCompatibility(),
112-
dto -> facade.createOrUpdateArtifactRule(subject, RuleType.COMPATIBILITY, dto),
113-
() -> facade.deleteArtifactRule(subject, RuleType.COMPATIBILITY));
117+
dto -> {
118+
if (!doesArtifactRuleExist(subject, RuleType.COMPATIBILITY, null)) {
119+
getStorage().createArtifactRule(null, subject, RuleType.COMPATIBILITY, dto);
120+
} else {
121+
getStorage().updateArtifactRule(null, subject, RuleType.COMPATIBILITY, dto);
122+
}
123+
},
124+
() -> {
125+
try {
126+
getStorage().deleteArtifactRule(null, subject, RuleType.COMPATIBILITY);
127+
} catch (RuleNotFoundException e) {
128+
//Ignore, fail only when the artifact is not found
129+
}
130+
});
114131
return request;
115132
}
116133

117134
@Override
118135
@Authorized(style=AuthorizedStyle.ArtifactOnly, level=AuthorizedLevel.Read)
119136
public CompatibilityLevelParamDto getSubjectCompatibilityLevel(String subject) {
120-
return getCompatibilityLevel(() ->
121-
facade.getArtifactRule(subject, RuleType.COMPATIBILITY).getConfiguration());
137+
return getCompatibilityLevel(() -> getStorage().getArtifactRule(null, subject, RuleType.COMPATIBILITY).getConfiguration());
122138
}
123139
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.apicurio.registry.ccompat.rest.v6.ModeResource;
2121
import io.apicurio.registry.ccompat.rest.error.Errors;
2222
import io.apicurio.common.apps.logging.Logged;
23+
import io.apicurio.registry.ccompat.rest.v7.impl.AbstractResource;
2324
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
2425
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
2526

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

+44-7
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,32 @@
1616

1717
package io.apicurio.registry.ccompat.rest.v6.impl;
1818

19+
import io.apicurio.common.apps.logging.Logged;
1920
import io.apicurio.registry.auth.Authorized;
2021
import io.apicurio.registry.auth.AuthorizedLevel;
2122
import io.apicurio.registry.auth.AuthorizedStyle;
2223
import io.apicurio.registry.ccompat.dto.SchemaInfo;
2324
import io.apicurio.registry.ccompat.dto.SubjectVersion;
2425
import io.apicurio.registry.ccompat.rest.v6.SchemasResource;
25-
import io.apicurio.common.apps.logging.Logged;
26+
import io.apicurio.registry.ccompat.rest.v7.impl.AbstractResource;
27+
import io.apicurio.registry.content.ContentHandle;
2628
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
2729
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
30+
import io.apicurio.registry.storage.ArtifactNotFoundException;
31+
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
32+
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
33+
import io.apicurio.registry.storage.dto.ContentWrapperDto;
34+
import io.apicurio.registry.storage.dto.StoredArtifactDto;
2835
import io.apicurio.registry.types.ArtifactType;
29-
36+
import io.apicurio.registry.util.ArtifactTypeUtil;
3037
import jakarta.interceptor.Interceptors;
38+
3139
import java.util.Arrays;
40+
import java.util.Collections;
3241
import java.util.List;
42+
import java.util.stream.Collectors;
43+
44+
import static io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior.DEFAULT;
3345

3446
/**
3547
* @author Ales Justin
@@ -40,19 +52,44 @@
4052
public class SchemasResourceImpl extends AbstractResource implements SchemasResource {
4153

4254
@Override
43-
@Authorized(style=AuthorizedStyle.GlobalId, level=AuthorizedLevel.Read)
55+
@Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read)
4456
public SchemaInfo getSchema(int id) {
45-
return facade.getSchemaById(id);
57+
ContentHandle contentHandle;
58+
List<ArtifactReferenceDto> references;
59+
if (getCconfig().getCanonicalHashModeEnabled().get()) {
60+
StoredArtifactDto artifactVersion = getStorage().getArtifactVersion(id);
61+
contentHandle = artifactVersion.getContent();
62+
references = artifactVersion.getReferences();
63+
} else {
64+
ContentWrapperDto contentWrapper = getStorage().getArtifactByContentId(id);
65+
contentHandle = getStorage().getArtifactByContentId(id).getContent();
66+
references = contentWrapper.getReferences();
67+
List<ArtifactMetaDataDto> artifacts = getStorage().getArtifactVersionsByContentId(id);
68+
if (artifacts == null || artifacts.isEmpty()) {
69+
//the contentId points to an orphaned content
70+
throw new ArtifactNotFoundException("ContentId: " + id);
71+
}
72+
}
73+
return getConverter().convert(contentHandle, ArtifactTypeUtil.determineArtifactType(contentHandle, null, null, getStorage().resolveReferences(references), getFactory().getAllArtifactTypes()), references);
4674
}
4775

4876
@Override
49-
@Authorized(style=AuthorizedStyle.GlobalId, level=AuthorizedLevel.Read)
77+
@Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read)
5078
public List<SubjectVersion> getSubjectVersions(int id) {
51-
return facade.getSubjectVersions(id);
79+
if (getCconfig().getLegacyIdModeEnabled().get()) {
80+
ArtifactMetaDataDto artifactMetaData = getStorage().getArtifactMetaData(id);
81+
return Collections.singletonList(getConverter().convert(artifactMetaData.getId(), artifactMetaData.getVersionId()));
82+
}
83+
84+
return getStorage().getArtifactVersionsByContentId(id)
85+
.stream()
86+
.filter(artifactMetaData -> isArtifactActive(artifactMetaData.getId(), artifactMetaData.getGroupId(), DEFAULT))
87+
.map(artifactMetaData -> getConverter().convert(artifactMetaData.getId(), artifactMetaData.getVersionId()))
88+
.collect(Collectors.toList());
5289
}
5390

5491
@Override
55-
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read)
92+
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
5693
public List<String> getRegisteredTypes() {
5794
return Arrays.asList(ArtifactType.JSON, ArtifactType.PROTOBUF, ArtifactType.AVRO);
5895
}

0 commit comments

Comments
 (0)