-
Notifications
You must be signed in to change notification settings - Fork 180
feat(21868): Introduce configurable network topology #21927
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
base: main
Are you sure you want to change the base?
feat(21868): Introduce configurable network topology #21927
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
7088108 to
52c7a22
Compare
Fixes hiero-ledger#21868 Allow users to configure mesh and geographic topologies before adding nodes. New: - MeshTopologyConfiguration record with builder methods - Network.withMeshTopology() to configure mesh topology - Network.withGeoMeshTopology() to configure geographic topology - TopologyConfigurationTest with 8 test cases Modified: - Network.java - Added configuration methods - AbstractNetwork.java - Factory pattern implementation - MeshTopologyImpl.java - Configuration support Design: - Pre-node configuration enforced (IllegalStateException if attempted after) - Factory pattern: Network creates topologies internally - Builder pattern: Immutable records with with...() methods - Fully backward compatible Usage: network.withMeshTopology( MeshTopologyConfiguration.DEFAULT .withAverageLatency(Duration.ofMillis(300)) .withJitter(Percentage.withPercentage(10)) ) .addNodes(4) .start(); Signed-off-by: kaldun-tech <[email protected]>
52c7a22 to
426530e
Compare
- Replace wildcard imports with explicit static imports in TopologyConfigurationTest - Add assertion messages to all JUnit and AssertJ assertions across test files - Remove unused private fields from AbstractNetwork Improves test diagnostics and removes dead code. Signed-off-by: kaldun-tech <[email protected]>
…changes Signed-off-by: kaldun-tech <[email protected]>
…s previously final and introducing a setter causes the warning to appear Signed-off-by: kaldun-tech <[email protected]>
|
The main issue I'm having here is the assignee check |
|
Hi @kaldun-tech! Sorry, I missed that your PR is ready for review. I set the assignee and the milestone. I will review your PR later, once I have determined the process. Can you please take a look at the conflict meanwhile? |
Signed-off-by: Taras <[email protected]>
|
@netopyr Thanks Michael, the conflict seemed straightforward to fix. My change updated the name of the topology field to internalTopology to clean up Codacy warnings. The incoming change just added a networkConfiguration field. |
netopyr
left a comment
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.
Thanks @kaldun-tech. Looks good so far. The only major change is to have a single additional method on Network.
| * @throws IllegalStateException if any nodes have already been added to the network | ||
| */ | ||
| @NonNull | ||
| Network withMeshTopology(@NonNull MeshTopologyConfiguration configuration); |
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.
There should be only one method to configure the topology. We plan to add more topology types later, and it would be excessive to have a method for each. This means you have to define a common interface or abstract class for both configuration classes.
Please rename the method to topology(), returning void. This would make it consistent with the "record-style setters" we use elsewhere.
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.
I agree creating this interface is sensible. It can be called TopologyConfiguration and these classes will implement that.
| private final Topology topology; | ||
| private final boolean useRandomNodeIds; | ||
|
|
||
| private Topology internalTopology; |
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.
Do you think there will be another topology? If there is an internal topology, I immediately wonder if there is a second one that is not internal.
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.
This was done to prevent Codacy warnings due to the name of the previously final variable being the same as the method. I tried to follow conventions observed in nearby classes. My personal habit would have been to name the methods as "getTopology setTopology"
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.
I'll rename it "currentTopology" to be more clear that there is a single topology
| @Override | ||
| @NonNull | ||
| public Network withMeshTopology(@NonNull final MeshTopologyConfiguration configuration) { | ||
| throwIfInLifecycle(Lifecycle.RUNNING, "Cannot configure topology while the network is running."); |
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.
It would be sufficient to check if we are in Lifecycle.INIT. Once the network was started, we should not change the topology.
| * before adding any nodes to the network using the new configuration objects | ||
| * and methods. | ||
| */ | ||
| class TopologyConfigurationTest { |
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.
This test does not cause harm, but we typically do not validate regular getters and setters. (Though, I would not be surprised if there are examples in our code base where we do exactly that. 😄 )
| * @throws IllegalStateException if any nodes have already been added to the network | ||
| */ | ||
| @NonNull | ||
| Network withGeoMeshTopology(@NonNull GeographicLatencyConfiguration configuration); |
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.
GeographicLatencyConfiguration should probably be renamed to make it more evident that its sole purpose is to configure a GeoMeshTopology. Maybe GeoMeshTopologyConfiguration.
|
@kaldun-tech thank you for your interest and contribution to the project! |
|
@poulok Thanks for the kind words! Planning to wrap up the PR today |
|
I had trouble with the integration tests. It looks like the testIntegration gradle task depends on :consensus-otter-docker-app:copyDockerizedApp which is not present in the build in my fork. Is this already addressed in another issue? |
I do not recall ever seeing such an issue. The task We had an issue, though, that one had to manually call |
- Created TopologyConfiguration marker interface - Unified withMeshTopology() and withGeoMeshTopology() into single topology() method - Simplified lifecycle validation to use throwIfNotInLifecycle(Lifecycle.INIT) - Renamed internal field: internalTopology → currentTopology Addresses maintainer feedback on PR hiero-ledger#21927 Signed-off-by: kaldun-tech <[email protected]>
Extract GeoMeshTopologyConfiguration from inline configuration logic into a dedicated record class that implements TopologyConfiguration. This improves code organization and reusability by providing a standardized way to define topology configurations with validation and builder-style methods. Changes: - Create GeoMeshTopologyConfiguration record with validation - Introduce TopologyConfiguration marker interface - Update GeoMeshTopologyImpl to use extracted configuration - Refactor GeoMeshTopology to use configuration object - Add TopologyConfigurationTest for validation tests - Apply spotless formatting fixes across related files This enables easier topology customization and testing in network fixtures. Signed-off-by: kaldun-tech <[email protected]>
…opologyConfiguration Signed-off-by: kaldun-tech <[email protected]>
Description:
Allow users to configure mesh and geographic topologies before adding nodes.
Related issue(s):
Fixes #21868
Notes for reviewer:
New:
Modified:
Design:
Checklist