Skip to content

Commit

Permalink
[REST API v3] Change how create-artifact and create-version APIs work! (
Browse files Browse the repository at this point in the history
#4671)

* Change how create-artifact and create-version APIs work!

* Fix python sdk tests

* Regenerated the go-sdk and fixed tests to use v3 of the api

* Basic fixes to the UI to use the new v3 REST API changes

* Fix broken UI tests

* Fixed artifact type discovery from content

* Fix default schema resolver to send content-type when making REST call

* Regen go sdk

* Fix lint issues

* Fix bug in dispatching create-artifact kafkasql message

* Fixed all broken examples

* Fix a problem in the canonical hash integration test

* Extract metadata only in v2 rest api

* Extract metadata when updating an artifact in the v2 api

* Fix new basic auth test
  • Loading branch information
EricWittmann authored May 16, 2024
1 parent 11b7e71 commit 855860c
Show file tree
Hide file tree
Showing 172 changed files with 5,334 additions and 7,824 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:

- name: Collect logs
if: failure()
run: ./.github/scripts/collect_logs.sh
run: sh ./.github/scripts/collect_logs.sh

- name: Upload tests logs artifacts
if: failure()
Expand Down Expand Up @@ -190,7 +190,7 @@ jobs:

- name: Collect logs
if: failure()
run: ./.github/scripts/collect_logs.sh
run: sh ./.github/scripts/collect_logs.sh

- name: Upload tests logs artifacts
if: failure()
Expand Down Expand Up @@ -236,7 +236,7 @@ jobs:

- name: Collect logs
if: failure()
run: ./.github/scripts/collect_logs.sh
run: sh ./.github/scripts/collect_logs.sh

- name: Upload tests logs artifacts
if: failure()
Expand Down Expand Up @@ -309,7 +309,7 @@ jobs:

- name: Collect logs
if: failure()
run: ./.github/scripts/collect_logs.sh
run: sh ./.github/scripts/collect_logs.sh

- name: Upload tests logs artifacts
if: failure()
Expand Down Expand Up @@ -347,7 +347,7 @@ jobs:
- name: Collect logs
if: failure()
run: ./.github/scripts/collect_logs.sh
run: sh ./.github/scripts/collect_logs.sh

- name: Upload tests logs artifacts
if: failure()
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target/

# IntelliJ / IDEA
.idea/
.run/
*.iml
*.ipr
*.iws
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
package io.apicurio.registry.ccompat.rest.v7.impl;


import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.avro.AvroTypeException;
import org.apache.avro.SchemaParseException;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;

import io.apicurio.registry.ccompat.dto.SchemaReference;
import io.apicurio.registry.ccompat.rest.error.ConflictException;
import io.apicurio.registry.ccompat.rest.error.UnprocessableEntityException;
Expand All @@ -27,17 +16,32 @@
import io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior;
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.ContentWrapperDto;
import io.apicurio.registry.storage.dto.EditableArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.EditableVersionMetaDataDto;
import io.apicurio.registry.storage.dto.StoredArtifactVersionDto;
import io.apicurio.registry.storage.error.ArtifactNotFoundException;
import io.apicurio.registry.storage.error.RuleNotFoundException;
import io.apicurio.registry.storage.error.VersionNotFoundException;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.ContentTypes;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.RuleType;
import io.apicurio.registry.types.VersionState;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
import io.apicurio.registry.util.ContentTypeUtil;
import jakarta.inject.Inject;
import org.apache.avro.AvroTypeException;
import org.apache.avro.SchemaParseException;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public abstract class AbstractResource {

Expand Down Expand Up @@ -68,13 +72,35 @@ protected ArtifactVersionMetaDataDto createOrUpdateArtifact(String subject, Stri
try {
ContentHandle schemaContent;
schemaContent = ContentHandle.create(schema);
String contentType = ContentTypes.APPLICATION_JSON;
if (artifactType.equals(ArtifactType.PROTOBUF)) {
contentType = ContentTypes.APPLICATION_PROTOBUF;
} else if (ContentTypeUtil.isParsableYaml(schemaContent)) {
contentType = ContentTypes.APPLICATION_YAML;
}

if (!doesArtifactExist(subject, groupId)) {
rulesService.applyRules(groupId, subject, artifactType, schemaContent, RuleApplicationType.CREATE, artifactReferences, resolvedReferences);
res = storage.createArtifact(groupId, subject, null, artifactType, schemaContent, parsedReferences);

EditableArtifactMetaDataDto artifactMetaData = EditableArtifactMetaDataDto.builder().build();
EditableVersionMetaDataDto firstVersionMetaData = EditableVersionMetaDataDto.builder().build();
ContentWrapperDto firstVersionContent = ContentWrapperDto.builder()
.content(schemaContent)
.contentType(contentType)
.references(parsedReferences)
.build();

res = storage.createArtifact(groupId, subject, artifactType, artifactMetaData, null,
firstVersionContent, firstVersionMetaData, null).getValue();
} else {
rulesService.applyRules(groupId, subject, artifactType, schemaContent, RuleApplicationType.UPDATE, artifactReferences, resolvedReferences);
res = storage.createArtifactVersion(groupId, subject, null, artifactType, schemaContent, parsedReferences);
ContentWrapperDto versionContent = ContentWrapperDto.builder()
.content(schemaContent)
.contentType(contentType)
.references(parsedReferences)
.build();
res = storage.createArtifactVersion(groupId, subject, null, artifactType, versionContent,
EditableVersionMetaDataDto.builder().build(), List.of());
}
} catch (RuleViolationException ex) {
if (ex.getRuleType() == RuleType.VALIDITY) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package io.apicurio.registry.ccompat.rest.v7.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import io.apicurio.common.apps.logging.Logged;
import io.apicurio.registry.auth.Authorized;
import io.apicurio.registry.auth.AuthorizedLevel;
Expand All @@ -24,6 +19,11 @@
import io.apicurio.registry.util.ArtifactTypeUtil;
import jakarta.interceptor.Interceptors;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
@Logged
public class SchemasResourceImpl extends AbstractResource implements SchemasResource {
Expand All @@ -32,17 +32,20 @@ public class SchemasResourceImpl extends AbstractResource implements SchemasReso
@Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read)
public SchemaInfo getSchema(int id, String subject, String groupId) {
ContentHandle contentHandle;
String contentType;
List<ArtifactReferenceDto> references;
if (cconfig.legacyIdModeEnabled.get()) {
StoredArtifactVersionDto artifactVersion = storage.getArtifactVersionContent(id);
contentHandle = artifactVersion.getContent();
contentType = artifactVersion.getContentType();
references = artifactVersion.getReferences();
} else {
ContentWrapperDto contentWrapper = storage.getContentById(id);
contentHandle = contentWrapper.getContent();
contentType = contentWrapper.getContentType();
references = contentWrapper.getReferences();
}
return converter.convert(contentHandle, ArtifactTypeUtil.determineArtifactType(contentHandle, null, null,
return converter.convert(contentHandle, ArtifactTypeUtil.determineArtifactType(contentHandle, null, contentType,
storage.resolveReferences(references), factory.getAllArtifactTypes()), references);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.apicurio.registry.storage.error.VersionNotFoundException;
import io.apicurio.registry.types.VersionState;
import io.apicurio.registry.util.ArtifactTypeUtil;
import io.apicurio.registry.util.ContentTypeUtil;
import io.apicurio.registry.util.VersionUtil;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
Expand Down Expand Up @@ -85,8 +86,12 @@ public SchemaId register(String subject, SchemaInfo request, Boolean normalize,

if (!idFound) {
try {
ContentHandle schemaContent = ContentHandle.create(request.getSchema());
String contentType = ContentTypeUtil.determineContentType(schemaContent);

// We validate the schema at creation time by inferring the type from the content
final String artifactType = ArtifactTypeUtil.determineArtifactType(ContentHandle.create(request.getSchema()), null, null, resolvedReferences, factory.getAllArtifactTypes());
final String artifactType = ArtifactTypeUtil.determineArtifactType(ContentHandle.create(request.getSchema()),
null, contentType, resolvedReferences, factory.getAllArtifactTypes());
if (request.getSchemaType() != null && !artifactType.equals(request.getSchemaType())) {
throw new UnprocessableEntityException(String.format("Given schema is not from type: %s", request.getSchemaType()));
}
Expand Down

This file was deleted.

Loading

0 comments on commit 855860c

Please sign in to comment.