Skip to content

Commit

Permalink
Fixed all broken examples
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed May 14, 2024
1 parent edb0e30 commit a36f822
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 101 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
2 changes: 1 addition & 1 deletion examples/avro-maven-with-references-auto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<file>
${project.basedir}/src/main/resources/schemas/TradeRaw.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<ifExists>FIND_OR_CREATE_VERSION</ifExists>
<canonicalize>true</canonicalize>
<analyzeDirectory>true</analyzeDirectory>
</artifact>
Expand Down
4 changes: 2 additions & 2 deletions examples/avro-maven-with-references/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<file>
${project.basedir}/src/main/resources/schemas/TradeKey.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<ifExists>FIND_OR_CREATE_VERSION</ifExists>
<canonicalize>true</canonicalize>
<references>
<reference>
Expand All @@ -48,7 +48,7 @@
<file>
${project.basedir}/src/main/resources/schemas/Exchange.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<ifExists>FIND_OR_CREATE_VERSION</ifExists>
<canonicalize>true</canonicalize>
</reference>
</references>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package io.apicurio.registry.examples.custom.resolver;

import io.apicurio.registry.rest.client.models.ArtifactContent;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.rest.client.models.CreateVersion;
import io.apicurio.registry.rest.client.models.IfArtifactExists;
import io.apicurio.registry.rest.client.models.VersionContent;
import io.apicurio.registry.serde.AbstractSchemaResolver;
import io.apicurio.registry.serde.ParsedSchema;
import io.apicurio.registry.serde.SchemaLookupResult;
Expand Down Expand Up @@ -69,15 +72,17 @@ public SchemaLookupResult<Schema> resolveSchema(String topic, Headers headers, D
ByteArrayInputStream schemaContent = new ByteArrayInputStream(schema.getBytes(StandardCharsets.UTF_8));
// Ensure the schema exists in the schema registry.

ArtifactContent content = new ArtifactContent();
CreateArtifact createArtifact = new CreateArtifact();
createArtifact.setArtifactId(artifactId);
createArtifact.setType(ArtifactType.AVRO);
createArtifact.setFirstVersion(new CreateVersion());
createArtifact.getFirstVersion().setContent(new VersionContent());
createArtifact.getFirstVersion().getContent().setContent(IoUtil.toString(schemaContent));
createArtifact.getFirstVersion().getContent().setContentType("application/json");

content.setContent(IoUtil.toString(schemaContent));

final io.apicurio.registry.rest.client.models.VersionMetaData metaData = client.groups().byGroupId("default").artifacts().post(content, config -> {
config.queryParameters.ifExists = io.apicurio.registry.rest.client.models.IfExists.RETURN_OR_UPDATE;
config.headers.add("X-Registry-ArtifactId", artifactId);
config.headers.add("X-Registry-ArtifactType", ArtifactType.AVRO);
});
final io.apicurio.registry.rest.client.models.VersionMetaData metaData = client.groups().byGroupId("default").artifacts().post(createArtifact, config -> {
config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION;
}).getVersion();

SchemaLookupResult result = SchemaLookupResult.builder()
.groupId(groupId)
Expand All @@ -102,9 +107,6 @@ public SchemaLookupResult<Schema> resolveSchemaByArtifactReference(ArtifactRefer
throw new UnsupportedOperationException("resolveSchemaByArtifactReference() is not supported by this implementation.");
}

/**
* @see io.apicurio.registry.serde.SchemaResolver#resolveSchemaByGlobalId(long)
*/
@Override
public SchemaLookupResult<Schema> resolveSchemaByGlobalId(long globalId) {
return super.resolveSchemaByGlobalId(globalId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.ArtifactContent;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.rest.client.models.CreateVersion;
import io.apicurio.registry.rest.client.models.IfArtifactExists;
import io.apicurio.registry.rest.client.models.VersionContent;
import io.apicurio.registry.serde.SerdeConfig;
import io.apicurio.registry.serde.avro.AvroKafkaDeserializer;
import io.apicurio.registry.serde.avro.AvroKafkaSerializer;
Expand Down Expand Up @@ -79,14 +82,16 @@ public static final void main(String[] args) throws Exception {

String artifactId = "my-artifact-" + topicName + "-value";

ArtifactContent content = new ArtifactContent();
CreateArtifact createArtifact = new CreateArtifact();
createArtifact.setArtifactId(artifactId);
createArtifact.setType(ArtifactType.AVRO);
createArtifact.setFirstVersion(new CreateVersion());
createArtifact.getFirstVersion().setContent(new VersionContent());
createArtifact.getFirstVersion().getContent().setContent(Config.SCHEMA);
createArtifact.getFirstVersion().getContent().setContentType("application/json");

content.setContent(Config.SCHEMA);

final io.apicurio.registry.rest.client.models.VersionMetaData metaData = client.groups().byGroupId("default").artifacts().post(content, config -> {
config.queryParameters.ifExists = io.apicurio.registry.rest.client.models.IfExists.RETURN;
config.headers.add("X-Registry-ArtifactId", artifactId);
config.headers.add("X-Registry-ArtifactType", ArtifactType.AVRO);
client.groups().byGroupId("default").artifacts().post(createArtifact, config -> {
config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION;
});

System.out.println("Created artifact " + artifactId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import io.apicurio.registry.resolver.SchemaResolverConfig;
import io.apicurio.registry.resolver.strategy.ArtifactReference;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.ArtifactContent;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.rest.client.models.CreateVersion;
import io.apicurio.registry.rest.client.models.IfArtifactExists;
import io.apicurio.registry.rest.client.models.VersionContent;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.utils.IoUtil;
import io.apicurio.schema.validation.json.JsonMetadata;
Expand Down Expand Up @@ -90,13 +93,18 @@ public static final void main(String[] args) throws Exception {
String artifactId = JsonSchemaValidationExample.class.getSimpleName();
RegistryClient client = createRegistryClient(REGISTRY_URL);

ArtifactContent artifactContent = new ArtifactContent();
artifactContent.setContent(IoUtil.toString(SCHEMA.getBytes(StandardCharsets.UTF_8)));

final io.apicurio.registry.rest.client.models.VersionMetaData metaData = client.groups().byGroupId("default").artifacts().post(artifactContent, config -> {
config.queryParameters.ifExists = io.apicurio.registry.rest.client.models.IfExists.RETURN_OR_UPDATE;
config.headers.add("X-Registry-ArtifactId", artifactId);
config.headers.add("X-Registry-ArtifactType", ArtifactType.JSON);
CreateArtifact createArtifact = new CreateArtifact();
createArtifact.setArtifactId(artifactId);
createArtifact.setType(ArtifactType.JSON);
createArtifact.setFirstVersion(new CreateVersion());
createArtifact.getFirstVersion().setContent(new VersionContent());
createArtifact.getFirstVersion().getContent().setContent(
IoUtil.toString(SCHEMA.getBytes(StandardCharsets.UTF_8))
);
createArtifact.getFirstVersion().getContent().setContentType("application/json");

client.groups().byGroupId("default").artifacts().post(createArtifact, config -> {
config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION;
});

// Create an artifact reference pointing to the artifact we just created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
import io.apicurio.registry.examples.AddressBookProtos.AddressBook;
import io.apicurio.registry.examples.AddressBookProtos.Person;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.ArtifactContent;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.rest.client.models.CreateVersion;
import io.apicurio.registry.rest.client.models.IfArtifactExists;
import io.apicurio.registry.rest.client.models.VersionContent;
import io.apicurio.registry.serde.SerdeConfig;
import io.apicurio.registry.serde.protobuf.ProtobufKafkaDeserializer;
import io.apicurio.registry.serde.protobuf.ProtobufKafkaSerializer;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.ContentTypes;
import io.apicurio.registry.utils.IoUtil;
import io.kiota.http.vertx.VertXRequestAdapter;
import org.apache.kafka.clients.consumer.ConsumerConfig;
Expand Down Expand Up @@ -85,16 +89,19 @@ public static final void main(String[] args) throws Exception {
System.out.println("Manually creating the artifact in Apicurio Registry");
//because the default ArtifactResolverStrategy is TopicIdStrategy the artifactId is in the form of topicName-value


String artifactId = topicName + "-value";
InputStream protofile = Thread.currentThread().getContextClassLoader().getResourceAsStream("person.proto");

ArtifactContent content = new ArtifactContent();
content.setContent(IoUtil.toString(protofile));
CreateArtifact createArtifact = new CreateArtifact();
createArtifact.setArtifactId(artifactId);
createArtifact.setType(ArtifactType.PROTOBUF);
createArtifact.setFirstVersion(new CreateVersion());
createArtifact.getFirstVersion().setContent(new VersionContent());
createArtifact.getFirstVersion().getContent().setContent(IoUtil.toString(protofile));
createArtifact.getFirstVersion().getContent().setContentType(ContentTypes.APPLICATION_PROTOBUF);

final io.apicurio.registry.rest.client.models.VersionMetaData personAmd = client.groups().byGroupId("default").artifacts().post(content, config -> {
config.queryParameters.ifExists = io.apicurio.registry.rest.client.models.IfExists.RETURN_OR_UPDATE;
config.headers.add("X-Registry-ArtifactId", topicName + "-value");
config.headers.add("X-Registry-ArtifactType", ArtifactType.PROTOBUF);
client.groups().byGroupId("default").artifacts().post(createArtifact, config -> {
config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION;
});

System.out.println();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
import io.apicurio.registry.resolver.SchemaResolverConfig;
import io.apicurio.registry.resolver.strategy.ArtifactReference;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.ArtifactContent;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.rest.client.models.CreateVersion;
import io.apicurio.registry.rest.client.models.IfArtifactExists;
import io.apicurio.registry.rest.client.models.VersionContent;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.ContentTypes;
import io.apicurio.registry.utils.IoUtil;
import io.apicurio.schema.validation.protobuf.ProtobufMetadata;
import io.apicurio.schema.validation.protobuf.ProtobufRecord;
Expand Down Expand Up @@ -81,13 +85,16 @@ public static final void main(String[] args) throws Exception {
String artifactId = ProtobufValidationExample.class.getSimpleName();
RegistryClient client = createRegistryClient(REGISTRY_URL);

ArtifactContent artifactContent = new ArtifactContent();
artifactContent.setContent(IoUtil.toString(SCHEMA.getBytes(StandardCharsets.UTF_8)));
CreateArtifact createArtifact = new CreateArtifact();
createArtifact.setArtifactId(artifactId);
createArtifact.setType(ArtifactType.PROTOBUF);
createArtifact.setFirstVersion(new CreateVersion());
createArtifact.getFirstVersion().setContent(new VersionContent());
createArtifact.getFirstVersion().getContent().setContent(IoUtil.toString(SCHEMA.getBytes(StandardCharsets.UTF_8)));
createArtifact.getFirstVersion().getContent().setContentType(ContentTypes.APPLICATION_PROTOBUF);

final io.apicurio.registry.rest.client.models.VersionMetaData metaData = client.groups().byGroupId("default").artifacts().post(artifactContent, config -> {
config.queryParameters.ifExists = io.apicurio.registry.rest.client.models.IfExists.RETURN_OR_UPDATE;
config.headers.add("X-Registry-ArtifactId", artifactId);
config.headers.add("X-Registry-ArtifactType", ArtifactType.PROTOBUF);
client.groups().byGroupId("default").artifacts().post(createArtifact, config -> {
config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION;
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

package io.apicurio.registry.examples;

import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.rest.client.models.CreateVersion;
import io.apicurio.registry.rest.client.models.IfArtifactExists;
import io.apicurio.registry.rest.client.models.VersionContent;
import io.apicurio.rest.client.util.IoUtil;
import io.kiota.http.vertx.VertXRequestAdapter;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.ArtifactContent;
import io.apicurio.rest.client.util.IoUtil;
import io.kiota.http.vertx.VertXRequestAdapter;

/**
* @author [email protected]
*/
Expand All @@ -51,13 +54,16 @@ public static void main(String[] args) throws Exception {
String content = template.replaceFirst("Apicurio Registry API", "Apicurio Registry API :: Copy #" + idx);
InputStream contentIS = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));

ArtifactContent artifactContent = new ArtifactContent();
artifactContent.setContent(IoUtil.toString(contentIS));
CreateArtifact createArtifact = new CreateArtifact();
createArtifact.setArtifactId("city");
createArtifact.setType("JSON");
createArtifact.setFirstVersion(new CreateVersion());
createArtifact.getFirstVersion().setContent(new VersionContent());
createArtifact.getFirstVersion().getContent().setContent(IoUtil.toString(contentIS));
createArtifact.getFirstVersion().getContent().setContentType("application/json");

final io.apicurio.registry.rest.client.models.VersionMetaData amdCity = client.groups().byGroupId("default").artifacts().post(artifactContent, config -> {
config.queryParameters.ifExists = io.apicurio.registry.rest.client.models.IfExists.RETURN_OR_UPDATE;
config.headers.add("X-Registry-ArtifactId", "city");
config.headers.add("X-Registry-ArtifactType", "JSON");
client.groups().byGroupId("default").artifacts().post(createArtifact, config -> {
config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION;
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.apicurio.registry.examples.util;

import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.ArtifactContent;
import io.apicurio.registry.rest.client.models.ArtifactMetaData;
import io.apicurio.registry.rest.client.models.IfExists;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.rest.client.models.CreateVersion;
import io.apicurio.registry.rest.client.models.IfArtifactExists;
import io.apicurio.registry.rest.client.models.VersionContent;
import io.apicurio.rest.client.util.IoUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,14 +30,17 @@ public static void createSchemaInServiceRegistry(RegistryClient service, String
try {
final ByteArrayInputStream content = new ByteArrayInputStream(schema.getBytes(StandardCharsets.UTF_8));

ArtifactContent artifactContent = new ArtifactContent();
artifactContent.setContent(IoUtil.toString(content));
CreateArtifact createArtifact = new CreateArtifact();
createArtifact.setArtifactId(artifactId);
createArtifact.setType("JSON");
createArtifact.setFirstVersion(new CreateVersion());
createArtifact.getFirstVersion().setContent(new VersionContent());
createArtifact.getFirstVersion().getContent().setContent(IoUtil.toString(content));
createArtifact.getFirstVersion().getContent().setContentType("application/json");

final io.apicurio.registry.rest.client.models.VersionMetaData metaData = service.groups().byGroupId("default").artifacts().post(artifactContent, config -> {
config.queryParameters.ifExists = IfExists.RETURN;
config.headers.add("X-Registry-ArtifactId", artifactId);
config.headers.add("X-Registry-ArtifactType", "JSON");
});
final io.apicurio.registry.rest.client.models.VersionMetaData metaData = service.groups().byGroupId("default").artifacts().post(createArtifact, config -> {
config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION;
}).getVersion();

assert metaData != null;
LOGGER.info("=====> Successfully created JSON Schema artifact in Service Registry: {}", metaData);
Expand Down
Loading

0 comments on commit a36f822

Please sign in to comment.