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

Open a RESTful API for Styx Object Store #406

Merged
merged 8 commits into from
May 16, 2019

Conversation

mikkokar
Copy link
Contributor

@mikkokar mikkokar commented May 2, 2019

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 on UrlPatternRouter. 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.

@mikkokar mikkokar requested review from kvosper and dvlato May 2, 2019 14:15
@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

val handler = RoutingObjectHandler(routeDatabase, objectFactory)

handler.handle(
HttpRequest.put("/admin/routing/objects/staticResponse")
Copy link
Contributor

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).

@mikkokar
Copy link
Contributor Author

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);
Copy link
Contributor

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);
Copy link
Contributor

@dvlato dvlato May 14, 2019

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?

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

static import?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@mikkokar mikkokar merged commit 385648f into ExpediaGroup:master May 16, 2019
@mikkokar mikkokar deleted the object-store-restful-api branch May 16, 2019 05:30
dvlato pushed a commit that referenced this pull request Jul 3, 2019
* Add UrlPatternRouter class.
* StyxObjectStore: Synchronous Insert/Remove, asynchronous watch notifications.
* HttpInterceptorPipeline "handler" to support named object references.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants