Introducing Podilizer: Automated Java code translator for AWS Lambda

by Josef Spillner

Overview

Function-as-a-Service (FaaS) is a relatively novel approach to run fine-grained code on the cloud. Almost all major cloud providers have opened such services in recent months. The approach still needs to be investigated in terms of evaluation, use-cases, performance and programmability. The first step of research was to overview the FaaS providers and to estimate their features and technical characteristics. The results were described in our previous blog-post. The FaaS paradigm allows one to write light-weight hosted functions targeted on a certain task and upload them to the cloud, or even author them online in Azure and Bluemix, for instance. But what if the user already has an existing application and would like to move it to a FaaS platform, or in marketing terms, to a “serverless” architecture. The Podilizer tool aims to perform an automated translation of existing Java code into uploadable functions and to deploy them to cloud in one go. This tool is related to research on the degree of automation and flexibility in terms of switching service technologies without development effort.

Tool description

Podilizer is an open source command line tool which translates Java code into AWS Lambda function units (i.e. functions and dependencies) and deploys them on the AWS FaaS implementation Lambda upon request.

The input data for tool is:

  • Correct (input) Java project – see README for constraints
  • AWS credentials in a configuration file (optional; only for automated deploying)

Tool output:

  • New (output) Java project which can invoke the functions remotely
  • Maven projects for each Lambda function
  • Built jars of each Lambda project
  • Deployed Lambda function (optional)

Lambda functions have a defined programming model which does not match well Java’s object oriented paradigm. Besides code written on Java operates with stateful objects, Lambda operates with so-called pure functions that should be stateless, as alternative to using a cloud-provided state where other cost incur (e.g. AWS S3). It was decided to keep states sending them to functions and restoring the instances after function performance. So far there are some object oriented features that are not fully supported for translation. In the future, we will look into alternative state handling techniques.

Architecture

The figure above shows the runtime architecture of the tool. It transforms an input output into an output project which is compiled into a set of Lambda functions units. Podilizer performs a static code analysis, a rewrite paired with code generation, and a compilation for every unit. All units are then uploaded to AWS. Each invocation causes a rated call at the AWS API gateway. This opens the potential for more research, for instance on optimised grouping of functions or on using non-rated internal network interfaces for these calls.

Example

This paragraph shows the actual Podilizer tool usage in practice with an intuitive sample Java application. The repository of the Podilizer tool can be found here. The example execution was performed under Ubuntu 16.04 with JDK v1.7. The first step is to clone the tool’s repository:

git clone https://github.com/serviceprototypinglab/podilizer

The project must be built by Maven so you need Maven to be installed. Additionally, the tool needs Maven at runtime to build the Lambda functions. The home directory for execution needs to be specified; otherwise it uses the default Maven path: /usr/share/maven/. If you have different one add the Maven home path (M2_HOME) as an environment variable. Then, after you have cloned the repository and setup Maven, go to the Podilizer folder and build it:

mvn install

Before running the tool you should copy ‘additional/conf/jyaml.yml.dist’ into ‘additional/conf/jyaml.yml’. Also if your input project uses some external libraries you should add appropriate maven dependencies to the ‘additional/conf/pom.xml’ file.
Then you can run Podilizer in translation mode using the following command:

java -jar target/Podilizer-0.1.jar -t [[option attribute]...] [-conf /path/to/conf/folder]

Or you can run it in translation+upload mode using the next command. In this case you need to add AWS credentials to ‘additional/conf/jyaml.yml’ file.

java -jar target/Podilizer-0.1.jar -tu ...

Basically ‘additional/conf/’ is considered as a default path of folder with configuration files (jyaml.yml, pom.xml). In both variants, the ‘-conf’ option is not necessary if you run the tool directly from Podilizer project source folder.
After the ‘-t’ and ‘-tu’ you can define paths of input and output projects to override any setting in the configuration file:

java -jar target/Podilizer-0.1.jar -t ~/podilizerExample/example/in/ ~/podilizerExample/example/out/

java -jar target/Podilizer-0.1.jar -tu ~/podilizerExample/example/in/ ~/podilizerExample/example/out/

You also can define those paths statically in the ‘additional/conf/jyaml.yml’ configuration file; in this case you do not define attributes for ‘-t’ or ‘-tu’ options. Being in the project folder, we can translate input Java code using this command without further configuration:

java -jar target/Podilizer-0.1.jar -t ~/podilizerExample/example/in/ ~/podilizerExample/example/out/

After running this command and waiting for it to finish, you see the Maven reports of each Lambda function building process. In this example a simple Java project with few classes and methods due to early tool stage was used. The test project was successfully translated and uploaded to AWS. You can find it by following the link.

More detailed instructions and limitation descriptions can be found in the tool’s README file.


Leave a Reply

Your email address will not be published. Required fields are marked *