Convert Lighty to JAXRS components#2013
Conversation
aa22659 to
9e1ebc7
Compare
|
26.3. - Rebased and fixing openapi |
bdd0619 to
d0f4272
Compare
|
OpenApi fixed, now fixing Http2 and Https |
d0f4272 to
69ef4de
Compare
69ef4de to
1d05889
Compare
1d05889 to
424ed33
Compare
9371b51 to
39eca7c
Compare
There was a problem hiding this comment.
Code Review
This pull request undertakes a significant refactoring to convert CommunityRestConf to use JaxRsEndpoint and transitions LightyServerBuilder to a new LightyJettyServerProvider that utilizes JettyWebServer from org.opendaylight.aaa.web.jetty. This aligns the server setup more closely with ODL's AAA web infrastructure, which is a positive direction.
However, there are some critical and medium severity concerns that need addressing, particularly the use of reflection to access private fields in JettyWebServer and the handling of WebContextSecurer for OpenAPI endpoints.
Summary of Findings
- Critical: Reflection to Access Private Fields:
Http2LightyServerBuilderandHttpsLightyServerBuilderuse reflection to access a privateserverfield inJettyWebServer. This is a highly fragile and problematic practice that breaks encapsulation and should be avoided. An alternative approach for configuring the Jetty server is necessary. - Medium: Unclear Usage of
contextsinLightyJettyServerProvider: TheLightyJettyServerProviderclass has acontextslist populated byaddContextHandlerbut doesn't seem to use this list to register contexts with the underlyingJettyWebServer. Its purpose is unclear. - Medium: Default No-Authentication for OpenAPI via
nullWebContextSecurer: Several modules and examples instantiateOpenApiLightywith anullWebContextSecurer, which defaults to a securer that disables authentication. This default behavior should be intentional and well-understood. - Low: Default
LightyWebContextSecurerBehavior (Not Commented): The defaultLightyWebContextSecurerinCommunityRestConf(and used byOpenApiLightyif no securer is provided) has emptyrequireAuthenticationmethods, effectively disabling authentication. The comment//do nothing since shiro is not usedis brief; more explanation on implications could be useful. - Low: Potential Typo in Method Name (Not Commented): The method
getjaxRsOpenApi()inOpenApiLighty.javaappears to have a typo and might be intended asgetJaxRsOpenApi()orgetOpenApiService(). - Low: Redundant Server Build in Test (Not Commented): In
LightyJettyServerProviderTest.testServerBuilder,serverBuilder.build()is called redundantly before the main test logic that also builds the server.
Merge Readiness
This pull request is a work-in-progress (as indicated by the WIP title) and introduces significant architectural changes by adopting JettyWebServer and JaxRsEndpoint. While the direction is promising, there are critical issues, primarily the use of reflection in Http2LightyServerBuilder and HttpsLightyServerBuilder, that must be addressed before this PR can be considered for merging. Additionally, there are medium-severity concerns regarding the clarity of LightyJettyServerProvider.contexts usage and the default authentication behavior for OpenAPI endpoints that should also be reviewed.
I am unable to approve pull requests. It is recommended that these changes, especially the critical ones, are resolved and then further reviewed by other maintainers before merging.
lighty-modules/lighty-jetty-server/src/main/java/io/lighty/server/Http2LightyServerBuilder.java
Outdated
Show resolved
Hide resolved
lighty-modules/lighty-jetty-server/src/main/java/io/lighty/server/HttpsLightyServerBuilder.java
Outdated
Show resolved
Hide resolved
...ty-modules/lighty-jetty-server/src/main/java/io/lighty/server/LightyJettyServerProvider.java
Outdated
Show resolved
Hide resolved
...gator/lighty-rnc-module/src/main/java/io/lighty/applications/rnc/module/RncLightyModule.java
Show resolved
Hide resolved
...ommunity-restconf-actions-app/src/main/java/io/lighty/examples/controllers/actions/Main.java
Show resolved
Hide resolved
...nity-restconf-netconf-app/src/main/java/io/lighty/examples/controllers/restconfapp/Main.java
Show resolved
Hide resolved
e161e9c to
254f993
Compare
7af7926 to
4f3ab50
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request undertakes a significant and beneficial refactoring by converting CommunityRestConf and related components to use the JaxRsEndpoint and ODL AAA's WebServer abstraction. This modernizes the Jetty integration, improves modularity, and aligns better with OpenDaylight's ecosystem. The introduction of LightyJettyWebServer and LightyJettyServerProvider is a key part of this.
While the direction is excellent, there are a few areas that could be refined, particularly around error handling and redundancy, as detailed in the comments. Given the "WIP" nature, these are likely points for further development.
Summary of Findings
- Error Handling in
OpenApiLightyInitialization: IfregisterWebContextfails duringOpenApiLightyinitialization, the error is logged, but the module might appear to initialize successfully. This can lead to aNullPointerExceptionduring shutdown. The initialization should fail more explicitly. - Exception Wrapping: In several places (
AAALightyShiroProvider,LightyJettyServerProvider),ServletExceptionis wrapped in a genericRuntimeException. This might obscure the original error type and could be reconsidered for better error diagnosis. - Redundant Null Checks in Server Builders:
Http2LightyServerBuilderandHttpsLightyServerBuildercontain redundant null checks for theserverfield in theirbuild()methods, as the server is already initialized in their constructors. - Architectural Improvement: The shift to using ODL AAA's
WebServerabstraction andJaxRsEndpointis a positive architectural change, promoting better modularity and integration.
Merge Readiness
This pull request is marked as 'WIP' and introduces substantial refactoring towards a more modern and modular web server integration. The changes are generally in a good direction. However, there's a high-severity issue in OpenApiLighty's error handling during initialization that needs to be addressed. Additionally, a few medium-severity points regarding exception wrapping and code redundancy should be considered.
Given the 'WIP' status and the identified issues (especially the high-severity one), I recommend addressing these points before merging. As an AI, I am not authorized to approve pull requests; please ensure further review and approval by authorized team members.
lighty-modules/lighty-openapi/src/main/java/io/lighty/openapi/OpenApiLighty.java
Show resolved
Hide resolved
| } catch (ServletException e) { | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
Wrapping ServletException in a generic RuntimeException can obscure the original error type for callers. Could a more specific unchecked exception be more appropriate here, or should initAAAonServer (and subsequently the constructor) declare throws ServletException if it's a recoverable or specifically handleable error at a higher level? If this is considered a fatal initialization error, RuntimeException might be acceptable, but it's worth considering the impact on error diagnosis and handling.
lighty-modules/lighty-jetty-server/src/main/java/io/lighty/server/Http2LightyServerBuilder.java
Outdated
Show resolved
Hide resolved
lighty-modules/lighty-jetty-server/src/main/java/io/lighty/server/HttpsLightyServerBuilder.java
Outdated
Show resolved
Hide resolved
| } catch (ServletException e) { | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
When a ServletException occurs during registerWebContext, it's caught and re-thrown as a generic RuntimeException. While this makes the build() method not declare ServletException, it might hide the specific nature of the problem from callers. Would it be more informative to either declare throws ServletException or use a custom, more specific unchecked exception that wraps the ServletException?
be5db6a to
7f131a5
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request undertakes a significant and largely positive refactoring to convert CommunityRestConf to use JaxRsEndpoint and to overhaul the Jetty server setup by introducing LightyJettyWebServer and LightyJettyServerProvider. This modernizes the server interaction, promoting better modularity and adherence to the WebServer interface for component registration (like AAA and OpenAPI).
The changes are extensive and touch upon core server initialization, AAA, OpenAPI, and RestConf modules. The overall direction appears solid. However, there's a critical issue in how Http2LightyServerBuilder and HttpsLightyServerBuilder are updated, potentially leading to unintended behavior with server listeners.
Given the 'WIP' status, this feedback aims to highlight key areas for review and refinement.
Summary of Findings
- Potential unintended HTTP listener in server builders:
Http2LightyServerBuilderandHttpsLightyServerBuilderre-initializethis.serverwithnew LightyJettyWebServer(). This constructor path forLightyJettyWebServersets up an HTTP connector on a random port. Consequently, the specialized builders might produce servers that listen on both the intended secure port and an additional random HTTP port. This was commented on with 'high' severity. - Refactoring of Server Infrastructure: The core refactoring introduces
LightyJettyWebServer(implementingWebServer) andLightyJettyServerProvider, replacing the olderLightyServerBuilderparadigm. This is a positive change for modularity, allowing components like RestConf, AAA, and OpenAPI to register themselves via theWebServerinterface. This was not commented on as it's the main goal of the PR and generally well-executed, aside from the server builder issue. - AAA Module Refactoring: The
AAALightyShiroProviderhas been significantly refactored to useWebInitializerfor setting up its servlets and filters, which is a cleaner approach than direct Jetty API manipulation. This was not commented on as it appears to be an improvement. - OpenAPI Module Refactoring:
OpenApiLightynow usesWebContext.builder()andWebServer.registerWebContext()for its setup, aligning with the new server infrastructure. This was not commented on as it's a positive change. - CommunityRestConf to JaxRsEndpoint Conversion:
CommunityRestConfnow leveragesJaxRsEndpoint, which itself uses theWebServerinterface for registration. This is the central theme of the PR and seems to be implemented correctly by removing direct Jetty servlet setup fromCommunityRestConf. This was not commented on as it's the primary goal.
Merge Readiness
This pull request is marked as 'WIP' and introduces substantial refactoring to the server initialization and component registration logic. While the overall direction towards using JaxRsEndpoint and a WebServer abstraction is commendable, there are high-severity issues in Http2LightyServerBuilder and HttpsLightyServerBuilder that could lead to unintended server behavior (extra HTTP listeners on random ports). These critical issues should be addressed before this PR is considered for merging. As an AI, I am not authorized to approve pull requests, but I recommend further review and resolution of the identified issues. Other parts of the refactoring appear to be well-structured.
lighty-modules/lighty-jetty-server/src/main/java/io/lighty/server/Http2LightyServerBuilder.java
Outdated
Show resolved
Hide resolved
lighty-modules/lighty-jetty-server/src/main/java/io/lighty/server/HttpsLightyServerBuilder.java
Outdated
Show resolved
Hide resolved
...ommunity-restconf-actions-app/src/main/java/io/lighty/examples/controllers/actions/Main.java
Outdated
Show resolved
Hide resolved
...nity-restconf-netconf-app/src/main/java/io/lighty/examples/controllers/restconfapp/Main.java
Outdated
Show resolved
Hide resolved
lighty-modules/lighty-aaa-aggregator/lighty-aaa/src/main/java/io/lighty/aaa/AAALighty.java
Outdated
Show resolved
Hide resolved
lighty-modules/lighty-aaa-aggregator/lighty-aaa/src/main/java/io/lighty/aaa/AAALighty.java
Outdated
Show resolved
Hide resolved
lighty-modules/lighty-openapi/src/main/java/io/lighty/openapi/OpenApiLighty.java
Outdated
Show resolved
Hide resolved
...ty/src/main/java/io/lighty/modules/northbound/restconf/community/impl/CommunityRestConf.java
Show resolved
Hide resolved
...main/java/io/lighty/modules/northbound/restconf/community/impl/CommunityRestConfBuilder.java
Outdated
Show resolved
Hide resolved
...ty-modules/lighty-jetty-server/src/main/java/io/lighty/server/LightyJettyServerProvider.java
Show resolved
Hide resolved
...odules/lighty-jetty-server/src/test/java/io/lighty/server/LightyJettyServerProviderTest.java
Show resolved
Hide resolved
This conversion is required in order to use JaxRsEndpoint and JaxRsOpenApi since they do not use regular server but WebServer. This patch basically replaces LightyServerBuilder with WebServerProvider which makes WebServer acessible everywhere in Lighty.io where it may be needed. This change made the build method redundant, and thus it was removed. JIRA: LIGHTY-329 Signed-off-by: tobias.pobocik <[email protected]>
There is no need to create restconf manually anymore thanks to JaxRsEndpoint. This patch relies on the previous JettyWebServerProvider patch since JaxRsEndpoint requires JettyWebServer instead of regular server. Now initialization order matters, and restconf has to be initialized after lighty services. JIRA: LIGHTY-329 Signed-off-by: tobias.pobocik <[email protected]>
7f131a5 to
9a0c493
Compare
Since JettyWebServer is being used, the entire AAA authorization can be modernized and simplified to run using WebInitializer. jersey-hk2 dependency needed to be added in order to properly inject filters such as cross-origin from customFilterAdapterConfig. JIRA: LIGHTY-329 Signed-off-by: tobias.pobocik <[email protected]>
9a0c493 to
e0d9b9b
Compare
Use the JettyWebServer to initialize OpenApi the same way as its done in ODL. Also add possibility to add WebContextSecurer to secure the /openapi endpoint. JIRA: LIGHTY-329 Signed-off-by: tobias.pobocik <[email protected]>
e0d9b9b to
4e2b598
Compare
This change also required us to convert LightyServerBuilder to use JettyWebServer since it is used in CommunityRestConf to initialize JaxRsEndpoint.