-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apicurio Registry integration with Avro+Protobuf ser/des support
Signed-off-by: Michael Edgar <[email protected]>
- Loading branch information
Showing
25 changed files
with
1,517 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
api/src/main/java/com/github/streamshub/console/api/SchemasResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.github.streamshub.console.api; | ||
|
||
import java.util.Collections; | ||
import java.util.Optional; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.eclipse.microprofile.openapi.annotations.media.Content; | ||
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; | ||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; | ||
import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.streamshub.console.api.support.serdes.ArtifactReferences; | ||
import com.github.streamshub.console.api.support.serdes.MultiformatSchemaParser; | ||
|
||
import io.apicurio.registry.resolver.DefaultSchemaResolver; | ||
import io.apicurio.registry.resolver.SchemaResolver; | ||
import io.apicurio.registry.rest.client.RegistryClient; | ||
import io.apicurio.registry.rest.client.RegistryClientFactory; | ||
|
||
@Path("/api/schemas/{schemaId}") | ||
@Tag(name = "Schema Registry Resources") | ||
public class SchemasResource { | ||
|
||
@Inject | ||
ObjectMapper objectMapper; | ||
|
||
SchemaResolver<Object, ?> schemaResolver; | ||
|
||
@PostConstruct | ||
void initialize() { | ||
String registryUrl = ConfigProvider.getConfig().getOptionalValue("console.registry.endpoint", String.class) | ||
// TODO: remove default | ||
.orElse("http://localhost:9080"); | ||
|
||
RegistryClient registryClient = RegistryClientFactory.create(registryUrl); | ||
schemaResolver = new DefaultSchemaResolver<>(); | ||
schemaResolver.setClient(registryClient); | ||
schemaResolver.configure(Collections.emptyMap(), new MultiformatSchemaParser<>(Collections.emptySet())); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@APIResponse(responseCode = "200", ref = "Configurations", content = @Content()) | ||
@APIResponse(responseCode = "404", ref = "NotFound") | ||
@APIResponse(responseCode = "500", ref = "ServerError") | ||
@APIResponse(responseCode = "504", ref = "ServerTimeout") | ||
public Response describeConfigs( | ||
@Parameter(description = "Schema identifier") | ||
@PathParam("schemaId") | ||
String schemaId) { | ||
|
||
var reference = ArtifactReferences.fromSchemaId(schemaId, objectMapper); | ||
var schema = schemaResolver.resolveSchemaByArtifactReference(reference); | ||
|
||
var response = Optional.ofNullable(schema) | ||
.map(s -> s.getParsedSchema()) | ||
.map(s -> s.getRawSchema()) | ||
.map(Response::ok) | ||
.orElseThrow(() -> new NotFoundException("No such schema")); | ||
|
||
return response.build(); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
api/src/main/java/com/github/streamshub/console/api/model/HasLinks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.streamshub.console.api.model; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
interface HasLinks<T> { | ||
|
||
Map<String, String> links(); | ||
|
||
void links(Map<String, String> links); | ||
|
||
default T addLink(String key, String value) { | ||
links(addEntry(links(), key, value)); | ||
@SuppressWarnings("unchecked") | ||
T t = (T) this; | ||
return t; | ||
} | ||
|
||
private static <K, V> Map<K, V> addEntry(Map<K, V> map, K key, V value) { | ||
if (map == null) { | ||
map = new LinkedHashMap<>(); | ||
} | ||
map.put(key, value); | ||
return map; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
api/src/main/java/com/github/streamshub/console/api/model/HasMeta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.streamshub.console.api.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
interface HasMeta<T> { | ||
|
||
JsonApiMeta meta(); | ||
|
||
void meta(JsonApiMeta meta); | ||
|
||
default JsonApiMeta metaFactory() { | ||
return new JsonApiMeta(); | ||
} | ||
|
||
@JsonIgnore | ||
default JsonApiMeta getOrCreateMeta() { | ||
JsonApiMeta meta = meta(); | ||
|
||
if (meta == null) { | ||
meta = metaFactory(); | ||
meta(meta); | ||
} | ||
|
||
return meta; | ||
} | ||
|
||
default Object meta(String key) { | ||
JsonApiMeta meta = meta(); | ||
return meta != null ? meta.get(key) : null; | ||
} | ||
|
||
default T addMeta(String key, Object value) { | ||
JsonApiMeta meta = getOrCreateMeta(); | ||
meta.put(key, value); | ||
@SuppressWarnings("unchecked") | ||
T t = (T) this; | ||
return t; | ||
} | ||
} |
Oops, something went wrong.