-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[Kinesis] add Scala kinesis-mock build behind feature flag #12559
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -1,28 +1,82 @@ | ||
import os | ||
from enum import StrEnum | ||
from functools import lru_cache | ||
from typing import List | ||
from typing import Any, List | ||
|
||
from localstack.packages import Package | ||
from localstack.packages.core import NodePackageInstaller | ||
from localstack.packages import InstallTarget, Package | ||
from localstack.packages.core import GitHubReleaseInstaller, NodePackageInstaller | ||
from localstack.packages.java import JavaInstallerMixin, java_package | ||
|
||
_KINESIS_MOCK_VERSION = os.environ.get("KINESIS_MOCK_VERSION") or "0.4.9" | ||
_KINESIS_MOCK_VERSION = os.environ.get("KINESIS_MOCK_VERSION") or "0.4.12" | ||
|
||
|
||
class KinesisMockPackage(Package[NodePackageInstaller]): | ||
def __init__(self, default_version: str = _KINESIS_MOCK_VERSION): | ||
class KinesisMockEngine(StrEnum): | ||
NODE = "node" | ||
SCALA = "scala" | ||
|
||
@classmethod | ||
def _missing_(cls, value: str | Any) -> str: | ||
# default to 'node' if invalid enum | ||
if not isinstance(value, str): | ||
return cls(cls.NODE) | ||
return cls.__members__.get(value.upper(), cls.NODE) | ||
|
||
|
||
class KinesisMockNodePackageInstaller(NodePackageInstaller): | ||
def __init__(self, version: str): | ||
super().__init__(package_name="kinesis-local", version=version) | ||
|
||
|
||
class KinesisMockScalaPackageInstaller(JavaInstallerMixin, GitHubReleaseInstaller): | ||
def __init__(self, version: str = _KINESIS_MOCK_VERSION): | ||
super().__init__( | ||
name="kinesis-local", tag=f"v{version}", github_slug="etspaceman/kinesis-mock" | ||
) | ||
|
||
# Kinesis Mock requires JRE 21+ | ||
self.java_version = "21" | ||
|
||
def _get_github_asset_name(self) -> str: | ||
return "kinesis-mock.jar" | ||
|
||
def _prepare_installation(self, target: InstallTarget) -> None: | ||
java_package.get_installer(self.java_version).install(target) | ||
|
||
def get_java_home(self) -> str | None: | ||
"""Override to use the specific Java version""" | ||
return java_package.get_installer(self.java_version).get_java_home() | ||
|
||
|
||
class KinesisMockScalaPackage(Package[KinesisMockScalaPackageInstaller]): | ||
def __init__( | ||
self, | ||
default_version: str = _KINESIS_MOCK_VERSION, | ||
): | ||
super().__init__(name="Kinesis Mock", default_version=default_version) | ||
|
||
@lru_cache | ||
def _get_installer(self, version: str) -> NodePackageInstaller: | ||
return KinesisMockPackageInstaller(version) | ||
def _get_installer(self, version: str) -> KinesisMockScalaPackageInstaller: | ||
return KinesisMockScalaPackageInstaller(version) | ||
|
||
def get_versions(self) -> List[str]: | ||
return [_KINESIS_MOCK_VERSION] | ||
return [_KINESIS_MOCK_VERSION] # Only supported on v0.4.12+ | ||
|
||
|
||
class KinesisMockPackageInstaller(NodePackageInstaller): | ||
def __init__(self, version: str): | ||
super().__init__(package_name="kinesis-local", version=version) | ||
class KinesisMockNodePackage(Package[KinesisMockNodePackageInstaller]): | ||
def __init__( | ||
self, | ||
default_version: str = _KINESIS_MOCK_VERSION, | ||
): | ||
super().__init__(name="Kinesis Mock", default_version=default_version) | ||
|
||
@lru_cache | ||
def _get_installer(self, version: str) -> KinesisMockNodePackageInstaller: | ||
return KinesisMockNodePackageInstaller(version) | ||
|
||
def get_versions(self) -> List[str]: | ||
return [_KINESIS_MOCK_VERSION] | ||
|
||
|
||
kinesismock_package = KinesisMockPackage() | ||
# leave as 'kinesismock_package' for backwards compatability | ||
kinesismock_package = KinesisMockNodePackage() | ||
kinesismock_scala_package = KinesisMockScalaPackage() |
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 |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import localstack.config as config | ||
from localstack.packages import Package, package | ||
|
||
|
||
@package(name="kinesis-mock") | ||
def kinesismock_package() -> Package: | ||
from localstack.services.kinesis.packages import kinesismock_package | ||
from localstack.services.kinesis.packages import ( | ||
KinesisMockEngine, | ||
kinesismock_package, | ||
kinesismock_scala_package, | ||
) | ||
|
||
if KinesisMockEngine(config.KINESIS_MOCK_PROVIDER_ENGINE) == KinesisMockEngine.SCALA: | ||
return kinesismock_scala_package | ||
gregfurman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return kinesismock_package |
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
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.
Nit: Not entirely happy with this fallback logic here - it is effectively unused, as we only ever check if it is scala anyway, and we would silently accept obviously wrong values. Also, if we ever switch the default, we have to do it in multiple places. Nothing to hold back the merge, but I think we could potentially make this easier.
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.
Yeah I suppose this is unideal but I wanted to make sure (since we're feature-flagging this strategy) that nothing gets broken if incorrect values are used. Definitely erring on the defensive side.
What have we done in past for situations like this?
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.
Usually we would fallback, but at least with a warning in the log.