Skip to content
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

Refactor AiCoreService class #201

Merged
merged 14 commits into from
Dec 3, 2024
Merged

Refactor AiCoreService class #201

merged 14 commits into from
Dec 3, 2024

Conversation

MatKuhr
Copy link
Member

@MatKuhr MatKuhr commented Nov 28, 2024

Context

Follow up of #79

This PR simplifies the core classes and reduces public API.

This comes at the cost of no longer supporting a flow where e.g. a scenario for a deployment lookup is given first, and a resource group given afterwards. Both now always have to be given together. This way, we avoid complicated state changes via side effects and potentially unexpected behavior.

Feature scope:

  • Refactor AiCoreService class
  • Fix race condition in DeploymentResolver
  • More comprehensive tests for DeploymentResolver

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Aligned changes with the JavaScript SDK
  • Documentation updated
  • Release notes updated

@@ -19,99 +19,104 @@
* scenario or for a model.
*/
@Slf4j
class DeploymentCache {
@RequiredArgsConstructor
class DeploymentResolver {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache is actually just the hashmap, the majority of this class is logic doing the resolution

} catch (final OpenApiRequestException e) {
log.error("Failed to load deployments into cache", e);
} catch (final RuntimeException e) {
throw new DeploymentResolutionException(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this now throws. Previously the subsequent NoSuchElementException would have an incomplete stack trace, missing this cause.

*/
@Nonnull
public AiCoreDeployment withResourceGroup(@Nonnull final String resourceGroup) {
aiCoreService.resourceGroup = resourceGroup;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a modification from the outside of another object, invisible for users. This has been refactored to no longer be needed


/** Container for an API client and destination. */
@FunctionalInterface
public interface AiCoreDestination {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name AiCoreDestination for me was a bit too close to the Destination, and after this refactoring this interface isn't really needed anymore. Together with the goal of reducing public API this was removed.

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class DeploymentResolverTest extends WireMockTestServer {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed from CacheTest and optimized, but the diff is too large for git to detect it as renaming

@MatKuhr MatKuhr added the please-review Request to review a pull-request label Nov 28, 2024
@MatKuhr MatKuhr marked this pull request as ready for review November 28, 2024 17:14
@MatKuhr
Copy link
Member Author

MatKuhr commented Dec 2, 2024

Added an alternative with a Builder: #211

Copy link
Contributor

@newtork newtork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@MatKuhr MatKuhr merged commit 6acbfd8 into main Dec 3, 2024
5 checks passed
@MatKuhr MatKuhr deleted the chore/refactor-core-classes branch December 3, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please-review Request to review a pull-request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants