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

Remove old application router #609

Closed

Conversation

mikkokar
Copy link
Contributor

@mikkokar mikkokar commented Feb 7, 2020

Summary

This draft PR demonstrates styx codebase when the old, monolithic application router code has been removed. The second part of this PR demonstrates the programmatic API for injecting configuration objects into Styx Core.

Part 1: Remove Application Router

Removal of the old application router reduces styx codebase about 10-12K lines.

Important: The Registry etc related classes will be going along with OriginInventory. Therefore, the MemoryBackedRegistry can no longer be used from Scala end-to-end tests. To keep the test coverage, all Scala end-to-end tests should be migrated to Kotlin functional test suite. The MemoryBackedRegistry provided a "back door" for configuring the old application router programmatically from Scala tests. The only alternative now is to use the styx RESTful admin interface API for reprogramming the routing object database. Just like the Kotlin e2e tests do.

Part 2: Programmatic Configuration Objects

Commits:

  • Poc 1
  • Poc 2

Styx (proxy server) was originally designed to be a stand-alone application, not a library. Therefore the bootstrapping API for building and starting a styx proxy server was a complete afterthought. The biggest obstacle for providing a bootstrap API so far has been the routing object model, which was designed entirely around styx YAML configuration. These two commits demonstrate how to lift this restriction.

Currently, on master YAML is the only way to instantiate routing objects. For example:

                routingObjects:
                  secure:
                    type: StaticResponse
                    config:
                      status: 200
                      content: "secure"
                  nonSecure:
                    type: StaticResponse
                    config:
                      status: 200
                      content: "non-secure"
                  nonSecure2:
                    type: StaticResponse
                    config:
                      status: 200
                      content: "non-secure 2"
                  pathMapper:
                    type: PathPrefixRouter
                    config:
                      routes:
                        - prefix: "/"
                          destination:
                              type: RefLookup
                              config:
                                name: nonSecure
                        - prefix: "/2/"
                          destination:
                              type: RefLookup
                              config:
                                name: nonSecure2
                servers:
                  myHttp:
                    type: HttpServer
                    config:
                      port: 0
                      handler: nonSecure
                  pathPrefixServer:
                    type: HttpServer
                    config:
                      port: 0
                      handler: pathMapper
                  myHttps:
                    type: HttpServer
                    config:
                      port: 0
                      handler: secure
                      tlsSettings:
                        certificateFile: $crtFile
                        certificateKeyFile: $keyFile
                        sslProvider: JDK

This PoC allows the above configuration to be injected programmatically in Java (or Kotlin) code:

    val styxServer = StyxServer(StyxServerComponents.Builder()
            .routingObject("secure", StaticResponse(status = 200, content = "secure"))
            .routingObject("nonSecure", StaticResponse(status = 200, content = "non-secure"))
            .routingObject("nonSecure2", StaticResponse(status = 200, content = "non-secure 2"))
            .routingObject("pathMapper",
                    PathPrefixRouter(listOf(
                            Route("/", RefLookup("nonSecure")),
                            Route("/2/", RefLookup("nonSecure2"))
                    )))
            .server("myHttp", StyxHttpServer(port = 0, handler = "nonSecure"))
            .server("pathPrefixServer", StyxHttpServer(port = 0, handler = "pathMapper"))
            .server("myHttps",
                    StyxHttpServer(
                            port = 0,
                            handler = "secure",
                            tlsSettings = StyxHttpServerTlsSettings(
                                    certificateFile = crtFile,
                                    certificateKeyFile = keyFile,
                                    sslProvider = "JDK"
                            )))
            .build())

Highlights:

  • There now is a clear separation between 1) Styx configuration object and its 2) instantiation.

  • The styx configuration objects are declarative data classes. They are the object's configuration. The configuration objects are for public consumption and they derive from StyxObject<T>. They have a build method to produce an instantiated object.

  • An instantiated object implements data-plane or control plane, etc behaviour. They are always in private scope, and implement the interface T. For routing objects, T is a RoutingObject, it is InetServer for server objects, etc.

  • Custom Jackson serialisers to serialise/deserialise between Yaml representation and StyxObject<T>.

  • There is no need to carry the yaml configuration around. The Yaml configuration is now deserialised to Styx objects, and injected into StyxServerComponents.

Comment out all dependant kotlin FT tests.
- ServerObjectSpec works from the yaml configuration.

Includes:
 - StyxObject interface for programmatic styx objects.
 - Jackson serialisers/deserialisers for Styx Objects.
- Parse Styx yaml configuration and inject routing objects in styx server.
@mikkokar mikkokar mentioned this pull request Feb 26, 2020
@kvosper
Copy link
Contributor

kvosper commented Mar 31, 2021

Closing old draft PR (no action for over 1 year)

@kvosper kvosper closed this Mar 31, 2021
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.

2 participants