generated from finos-labs/project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 93
feat(calm-hub): decorator resource and endpoint to get decorators #2212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harveymmaunders
wants to merge
7
commits into
finos:main
Choose a base branch
from
harveymmaunders:feat/decorator-storage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6ec8fb3
feat(calm-hub): add decorators seed data to MongoDB initialization
harveymmaunders b3e54d3
feat(calm-hub): add decorators resource with GET endpoint
harveymmaunders b91f3f0
feat(calm-hub): add decorator filtering by target and type
harveymmaunders d4685a0
Merge branch 'main' into feat/decorator-storage
harveymmaunders 395ebf0
refactor(calm-hub): improve decorator query validation and storage layer
harveymmaunders 65f923c
chore(calm-hub): remove wilcard import
harveymmaunders 794cb2e
chore(calm-hub): update init mongo to include correct applies-to
harveymmaunders File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
calm-hub/src/main/java/org/finos/calm/resources/DecoratorResource.java
This file contains hidden or 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,69 @@ | ||
| package org.finos.calm.resources; | ||
|
|
||
| import jakarta.inject.Inject; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import jakarta.validation.constraints.Size; | ||
| import jakarta.ws.rs.GET; | ||
| import jakarta.ws.rs.Path; | ||
| import jakarta.ws.rs.PathParam; | ||
| import jakarta.ws.rs.Produces; | ||
| import jakarta.ws.rs.QueryParam; | ||
| import jakarta.ws.rs.core.MediaType; | ||
| import jakarta.ws.rs.core.Response; | ||
| import org.eclipse.microprofile.openapi.annotations.Operation; | ||
| import org.finos.calm.domain.ValueWrapper; | ||
| import org.finos.calm.domain.exception.NamespaceNotFoundException; | ||
| import org.finos.calm.security.CalmHubScopes; | ||
| import org.finos.calm.security.PermittedScopes; | ||
| import org.finos.calm.store.DecoratorStore; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import static org.finos.calm.resources.ResourceValidationConstants.NAMESPACE_MESSAGE; | ||
| import static org.finos.calm.resources.ResourceValidationConstants.NAMESPACE_REGEX; | ||
| import static org.finos.calm.resources.ResourceValidationConstants.QUERY_PARAM_NO_WHITESPACE_MESSAGE; | ||
| import static org.finos.calm.resources.ResourceValidationConstants.QUERY_PARAM_NO_WHITESPACE_REGEX; | ||
|
|
||
| /** | ||
| * Resource for managing decorators in a given namespace | ||
| */ | ||
| @Path("/calm/namespaces") | ||
| public class DecoratorResource { | ||
|
|
||
| private final DecoratorStore decoratorStore; | ||
| private final Logger logger = LoggerFactory.getLogger(DecoratorResource.class); | ||
|
|
||
| @Inject | ||
| public DecoratorResource(DecoratorStore decoratorStore) { | ||
| this.decoratorStore = decoratorStore; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve a list of decorator IDs in a given namespace with optional filtering | ||
| * | ||
| * @param namespace the namespace to retrieve decorators for | ||
| * @param target optional target path to filter by (e.g., "/calm/namespaces/finos/architectures/1/versions/1-0-0") | ||
| * @param type optional decorator type to filter by (e.g., "deployment", "observability") | ||
| * @return a list of decorator IDs matching the criteria | ||
| */ | ||
| @GET | ||
| @Path("{namespace}/decorators") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @Operation( | ||
| summary = "Retrieve decorators in a given namespace", | ||
| description = "Decorator IDs stored in a given namespace, optionally filtered by target and/or type" | ||
| ) | ||
| @PermittedScopes({CalmHubScopes.ARCHITECTURES_ALL, CalmHubScopes.ARCHITECTURES_READ}) | ||
| public Response getDecoratorsForNamespace( | ||
| @PathParam("namespace") @Pattern(regexp = NAMESPACE_REGEX, message = NAMESPACE_MESSAGE) String namespace, | ||
| @QueryParam("target") @Size(max = 500) @Pattern(regexp = QUERY_PARAM_NO_WHITESPACE_REGEX, message = QUERY_PARAM_NO_WHITESPACE_MESSAGE) String target, | ||
| @QueryParam("type") @Size(max = 100) @Pattern(regexp = QUERY_PARAM_NO_WHITESPACE_REGEX, message = QUERY_PARAM_NO_WHITESPACE_MESSAGE) String type | ||
| ) { | ||
| try { | ||
| return Response.ok(new ValueWrapper<>(decoratorStore.getDecoratorsForNamespace(namespace, target, type))).build(); | ||
| } catch (NamespaceNotFoundException e) { | ||
| logger.error("Invalid namespace [{}] when retrieving decorators", namespace, e); | ||
| return CalmResourceErrorResponses.invalidNamespaceResponse(namespace); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
calm-hub/src/main/java/org/finos/calm/store/DecoratorStore.java
This file contains hidden or 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,22 @@ | ||
| package org.finos.calm.store; | ||
|
|
||
| import org.finos.calm.domain.exception.NamespaceNotFoundException; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Interface for decorator storage operations. | ||
| */ | ||
| public interface DecoratorStore { | ||
|
|
||
| /** | ||
| * Retrieve decorator IDs for a given namespace with optional filtering. | ||
| * | ||
| * @param namespace the namespace to retrieve decorators for | ||
| * @param target optional target path to filter by (e.g., "/calm/namespaces/finos/architectures/1/versions/1-0-0") | ||
| * @param type optional decorator type to filter by (e.g., "deployment", "observability") | ||
| * @return a list of decorator IDs matching the criteria | ||
| * @throws NamespaceNotFoundException if the namespace does not exist | ||
| */ | ||
| List<Integer> getDecoratorsForNamespace(String namespace, String target, String type) throws NamespaceNotFoundException; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure how I feel about this target reference. We can include architecture id, but how do differ between pattersn / architectures and also the version>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, this is currently how MongoDB and CALM Hub have been setup. This follows the rest of how CALM Hub works and when this is changed, it will be updated along with the rest #1853.