A Serverless Framework for Kotlin

A Serverless Framework for Kotlin

Kotless: a Serverless Framework for Kotlin Vladislav Tankov Yaroslav Golubev Timofey Bryksin JetBrains JetBrains Research JetBrains Research ITMO University ITMO University Saint-Petersburg State University Email: [email protected] Email: [email protected] Email: [email protected] Abstract—Recent trends in Web development demonstrate an In this paper, we present Kotless — a serverless framework increased interest in serverless applications, i.e. applications that for Kotlin applications, which is open-source and available on utilize computational resources provided by cloud services on GitHub.1 The idea of Kotless is to provide a cloud-agnostic demand instead of requiring traditional server management. This approach enables better resource management while being DSL that unites the cloud service provider’s SDK and the scalable, reliable, and cost-effective. However, it comes with a deployment DSL. Using Kotless, a developer simply writes number of organizational and technical difficulties which stem an application in terms of event-driven architecture and the from the interaction between the application and the cloud deployment code is generated automatically straight from the infrastructure, for example, having to set up a recurring task source code. of reuploading updated files. In this paper, we present Kotless — a Kotlin Serverless Framework. Kotless is a cloud-agnostic Our approach eliminates the need for a specific deploy- toolkit that solves these problems by interweaving the deployed ment DSL and makes serverless computing comprehensible to application into the cloud infrastructure and automatically gen- anyone familiar with event-based architectures. For example, erating the necessary deployment code. This relieves developers a developer only needs to be familiar with JAX-RS2-like from having to spend their time integrating and managing their annotations to create and deploy a REST API application applications instead of developing them. Kotless has proven its capabilities and has been used to develop several serverless based on Kotless. applications already in production. Its source code is available at https://github.com/JetBrains/kotless, a tool demo can be found II. OVERVIEW at https://www.youtube.com/watch?v=IMSakPNl3TY. The main idea of Kotless is to interweave the deployed I. INTRODUCTION application into the deployment infrastructure — to create a framework that allows to use certain cloud services in the The term serverless computing refers to the concept of application’s code and then automatically create an appropriate building and running applications that do not require tradi- infrastructure tailored for this application. tional server management [1]. Such execution model implies To demonstrate this idea let us consider an example of a that applications are uploaded to a cloud service provider’s very basic web application that needs to host static files and infrastructure bundled as one or several functions. Then they provide access to them via HTTP. Normally, its developers are executed on demand, automatically scaled if needed, and would ask the IT department to configure an HTTP server billed according to the exact time these applications have been for them or to create an Amazon S3 bucket. Then a recurring running. This approach liberates developers from the burden task is to upload new files after each new deployment of this of maintaining their own hardware infrastructure and allows application — quite a lot of work overall. With Kotless, this to focus more on software [2]. task could be described with the snippet of Kotlin code shown Unfortunately, developers cannot simply upload the code to in Listing 1. a cloud service provider, they have to deploy it. To support arXiv:2105.13866v1 [cs.DC] 21 May 2021 that, the application should be implemented in an event- @StaticGet("/style.css", MimeType.CSS) driven way, providing certain functions which are triggered by val style = File("css/style.css") internal cloud events or incoming HTTP requests [3]. Thus, Listing 1. A fragment of a web application written with Kotless the deployment process of a serverless application requires defining a list of specific events that the application uses and In this example, the StaticGet annotation represents a endpoints it provides. For all major cloud service providers, cloud service request for a static resource accessible via HTTP. this is done using custom deployment domain-specific lan- Kotless deployment tools find this request and make sure that guages, or DSLs. Despite the fact that almost all interaction the cloud infrastructure stores the necessary resource. And between the cloud infrastructure and the application is defined moreover, this resource (a CSS file in this example) will be within the application’s code, it is still necessary to write a lot re-deployed when it changes. of boilerplate code, which often redefines constructs that are already present in the deployment DSL code. Moreover, the 1https://github.com/JetBrains/kotless total amount of deployment code in a complex application may 2JAX-RS is a Java API for RESTful web services, described in JSR311: even be comparable to the size of the application itself. https://jcp.org/en/jsr/detail?id=311 Kotless DSL Parser is an library capable of parsing Kotlin code and extracting declarations (for example, annotations in Listing 1) of Kotless DSL. It is based on the embeddable version of Kotlin compiler and can be used not only from Gradle, but from any Java application (for example, from an integrated development environment, such as IntelliJ IDEA). It parses the application code and generates a Kotless Schema object. Kotless Schema is a cloud-agnostic serverless model that defines available serverless resources, such as dynamic and static HTTP routes, serverless functions, and others. Each Kotless Schema object represents resources that should be deployed for this particular application. This object is then Fig. 1. Kotless pipeline passed to Kotless Terraform Synthesizer, which uses it to generate pretty-printed Terraform code. The generation of pretty-printed code includes not only formatting the code but Other cloud services (dynamic HTTP handlers, permissions, also its separation into groups by types of services and sorting etc.) are handled in a similar fashion. In practice, this approach them within each group according to resource dependencies. is extensible to any available cloud service provider or even After the Terraform code is generated, Kotless plugin self-hosted solutions like OpenShift. prepares a distributable jar file of the application with all III. ARCHITECTURE AND TOOL DETAILS the necessary dependencies and deploys it with generated deployment code. However, the work of Kotless does not stop Kotless is a Kotlin framework that consists of two major on the developer’s side. The framework also handles requests parts: to the application from the cloud in runtime and dispatches • Kotless DSL — a client-side DSL, distributed in the form them in accordance with the obtained Schema description. of a library; • Kotless plugin — a deployment tool, distributed in the B. Kotless DSL form of a Gradle plugin. Kotless DSL is a set of interfaces for various subsystems It is worth noting that Kotless does not interact with the that helps developers build serverless applications. It is used cloud provider itself, instead, it generates Terraform code. both during the deployment stage and in runtime, which means 3 Terraform is one of the popular deployment DSLs and is that certain DSL constructs will be firstly used to allocate all described in more detail in Section V. In this work, it is used the necessary cloud services, and later the same constructs as a kind of a cloud bytecode: the Terraform code is generated will handle the interaction between the application and the by Kotless to perform the actual deployment of the application. allocated services. For example, Get annotation is used to Now, let us take a look at the entire pipeline to see how the generate HTTP routes during the deployment stage and to source code written with Kotless becomes a fully deployed dispatch requests in runtime. In order for that to work, the serverless web application (Figure 1) and then overview the deployment tool must be integrated into the application, which main capabilities of Kotless DSL and Kotless plugin internals. was one of the main reasons for creating Kotless in the first A. Kotless pipeline place. The DSL consists of three major components. First of all, Kotless DSL is used to define HTTP endpoints 1) HTTP API: This component includes annotations for and other resources that exist in the cloud (e.g. database tables, creating HTTP routes, deploying static files, extensible serial- object storage, etc.). The DSL is cloud-agnostic, meaning that ization, and intercepting HTTP requests. HTTP API provides if the developer decides to switch from one cloud service everything that a standard library of a Web framework is provider to another, no changes in the application code will be expected to provide. However, one of the major elements of required to re-deploy the application (of course, only in case this API is a Dynamic route construct. Dynamic routes are the application is not integrated with cloud-specific services Kotlin functions annotated with Get or P ost, which create used outside of Kotless abstractions). new HTTP handlers with an appropriate HTTP method. In Before the first deployment, the developer sets up creden- case these functions have parameters or return a result of a tials to access the cloud provider, as well as some configuration primitive type, the API performs automatic deserialization of parameters that define the storage that Kotless might utilize. such values. To extend this feature to non-primitive types the Once that is over with, the developer executes the deployment programmer has to implement a conversion service object. task of the Kotless Gradle plugin. This task prepares the en- An example of a dynamic Get route is shown in Listing 2. vironment (downloads Terraform, allocates temporary storage, When the root page is requested, the application returns etc.) and launches Kotless DSL Parser.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us