-
Notifications
You must be signed in to change notification settings - Fork 79
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 a RESTful API for Styx Object Store #406
Open a RESTful API for Styx Object Store #406
Conversation
- RoutingObjectHandler - UrlPatternRouter - Wired up into admin server
components/proxy/src/main/java/com/hotels/styx/admin/AdminServerBuilder.java
Outdated
Show resolved
Hide resolved
@@ -122,6 +131,11 @@ private StandardHttpRouter adminEndpoints(StyxConfig styxConfig) { | |||
httpRouter.add("/admin/configuration/logging", new LoggingConfigurationHandler(styxConfig.startupConfig().logConfigLocation())); | |||
httpRouter.add("/admin/configuration/startup", new StartupConfigHandler(styxConfig.startupConfig())); | |||
|
|||
RoutingObjectHandler routingObjectHandler = new RoutingObjectHandler(routeDatabase, routingObjectFactory); | |||
httpRouter.add("/admin/routing", routingObjectHandler); |
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.
If /admin/routing
and /admin/routing/
are not considered equivalent, we should make a change to the httpRouter
instead of duplicating code.
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 think this is necessary because StandardHttpRouter
treats the two endpoints differently. But I'll have another look.
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 see we have this also for the metrics handler, but not for any others (
httpRouter.add("/admin/metrics", metricsHandler);
httpRouter.add("/admin/metrics/", metricsHandler);
)
I think this needs reviewing to identify any fixes we might need. I would say fixes can go in another PR.
components/proxy/src/main/java/com/hotels/styx/admin/handlers/RoutingObjectHandler.java
Outdated
Show resolved
Hide resolved
components/proxy/src/main/java/com/hotels/styx/admin/handlers/RoutingObjectHandler.java
Outdated
Show resolved
Hide resolved
components/proxy/src/main/java/com/hotels/styx/admin/handlers/RoutingObjectHandler.java
Outdated
Show resolved
Hide resolved
val handler = RoutingObjectHandler(routeDatabase, objectFactory) | ||
|
||
handler.handle( | ||
HttpRequest.put("/admin/routing/objects/staticResponse") |
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 are lots of tests that are set up this way. There should be some kind of shared setUp method for them (not for the test name Injecting new objects
though, since the put
is the thing being tested there).
components/proxy/src/test/kotlin/com/hotels/styx/admin/handlers/RoutingObjectHandlerTest.kt
Outdated
Show resolved
Hide resolved
components/proxy/src/test/kotlin/com/hotels/styx/admin/handlers/UrlPatternRouterTest.kt
Outdated
Show resolved
Hide resolved
components/proxy/src/test/kotlin/com/hotels/styx/routing/db/StyxObjectStoreTest.kt
Outdated
Show resolved
Hide resolved
components/proxy/src/test/kotlin/com/hotels/styx/routing/db/StyxObjectStoreTest.kt
Outdated
Show resolved
Hide resolved
Add functional tests for routing object REST API.
Added functional tests. |
@@ -122,6 +131,11 @@ private StandardHttpRouter adminEndpoints(StyxConfig styxConfig) { | |||
httpRouter.add("/admin/configuration/logging", new LoggingConfigurationHandler(styxConfig.startupConfig().logConfigLocation())); | |||
httpRouter.add("/admin/configuration/startup", new StartupConfigHandler(styxConfig.startupConfig())); | |||
|
|||
RoutingObjectHandler routingObjectHandler = new RoutingObjectHandler(routeDatabase, routingObjectFactory); | |||
httpRouter.add("/admin/routing", routingObjectHandler); |
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 see we have this also for the metrics handler, but not for any others (
httpRouter.add("/admin/metrics", metricsHandler);
httpRouter.add("/admin/metrics/", metricsHandler);
)
I think this needs reviewing to identify any fixes we might need. I would say fixes can go in another PR.
@@ -81,7 +81,7 @@ public RoutingObjectHandler(StyxObjectStore<RoutingObjectRecord> routeDatabase, | |||
|
|||
try { | |||
String object = routeDatabase.get(name) | |||
.map(record-> serialise(name, record)) | |||
.map(record -> serialise(name, record)) | |||
.orElseThrow(ResourceNotFoundException::new); |
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.
Are we logging the name of the resource that couldn't be found anywhere?
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.
No.
private static final String PLACEHOLDERS_KEY = "UrlRouter.placeholders"; | ||
private final List<RouteDescriptor> alternatives; | ||
|
||
private UrlPatternRouter(List<RouteDescriptor> alternatives) { | ||
this.alternatives = alternatives; | ||
this.alternatives = ImmutableList.copyOf(alternatives); |
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.
static import?
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.
Normally ImmutableList.copyOf
has been exempt from static imports.
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.
To clarify, we try to use static imports when the key information is in the method name, which makes the class name just clutter. In this case, the method name alone is insufficient to demonstrate that we are instantiating an immutable list.
components/proxy/src/main/java/com/hotels/styx/admin/handlers/UrlPatternRouter.java
Outdated
Show resolved
Hide resolved
components/proxy/src/main/java/com/hotels/styx/admin/handlers/UrlPatternRouter.java
Show resolved
Hide resolved
components/proxy/src/main/kotlin/com/hotels/styx/routing/db/StyxObjectStore.kt
Show resolved
Hide resolved
* Add UrlPatternRouter class. * StyxObjectStore: Synchronous Insert/Remove, asynchronous watch notifications. * HttpInterceptorPipeline "handler" to support named object references.
I'm adding a new
UrlPatternRouter
. To configure this router, you specify a regular expression pattern for each endpoint per HTTP verb. It also captures patterns from URL and exposes them as values in HTTP context. See the unit tests as an example.I have also added a new
RoutingObjectHandler
that builds onUrlPatternRouter
. It allows Styx Routing Object Store to be modified via RESTful API. It supports, addition, removal, and replacement of routing objects.The ObjectStore is updated accordingly, to support these features. Notice that ObjectStore concurrency model is improved. Object store modifications (insert/remove) now take place, always, in the calling thread. The executor simply delivers the watch notifications.