Multipurpose Framework for Rapid Application Server Prototyping with Java 8

There are many frameworks out there that do a great job at doing what they do. Selecting a right one can be very challenging and everyone applies their own preferences to the decision making process.

Sometimes I find myself needing something in between nothing (e.g. just simple java project) and everything (full blown Java Framework, with proper backend, REST, proper hardware, …). This is usually when I need to process a big chunk of data or quickly store some data collected on mobile app and analyze it later or backup images to somewhere reliable or just resize a lot of images that are in some remote location, …. and I want to do it fast, like so:

  1. git clone https://github.com/igorrendulic/rapido-java
  2. Eclipse Import: Debug As -> Java Application
  3. Write my code
  4. make deployall

Sometimes I need a REST interface which can be accessed from Mobile Apps. Another time I might need a database or a Task Queue. In some cases I might need 1TB disk in other cases 1GB would be sufficient. At times I require computationally intensive server at other times I don’t care about it. There are countless needs and almost every need can be met by googling, finding appropriate framework and browsing through StackOverflow if someone else encountered similar problems when assembling the selected framework. Unless you’re very familiar with the framework and have done exactly same setup before hiccups are almost inevitable.

I decided I needed something much simpler so I focused on:

  1. Framework
  2. Easy deployment

Framework

There is no way I could exactly foresee what I’ll need in the future. Therefore nothing can beat a simplistic configuration .

The framework itself is built to run on embedded Jetty 9.4.x server with Jersey for REST interface and Java 8. It supports plain old servlets and html rendering.

If you’re cloning the GitHub repository please be aware that the framework itself doesn’t include any security configuration and that CORS is enabled by default.

Used locally the framework can be cloned and imported into Eclipse or your favorite Development Tool. Simply run or “Debug as Java Application” with file com.igor.app.App.java and start coding.

git clone https://github.com/igorrendulic/rapido-java

Visit website: http://localhost:8080

Hosting on Google Cloud

Requirements

Install gcloud, Kuberenetes and Docker enable the Compute Engine Instance Group Manager API in the Google Cloud developers console.

For hosting I’ve chosen Google Cloud Container Engine. It might be an overkill but the Framework can be deployed to any hosting with any OS that supports Java 8 VM.

I didn’t go with “ServerLess Architecture” here because vendors usually have restrictions on how much and what can be done.

I chose Google Cloud because it’s fairly flexible with databases I might need or file storage or even BigQuery for data exploration. Once you learn how to include one of the services in your project others are easy as π.

There is also other benefits such as:

  • I can spin for example 120GB RAM machine or 0.5 GB
  • I can reserve 1TB disk or 10GB
  • I can expose the server to the internet or keep it behind a firewall
  • Simple access to logs through Google Console

Google offers a lot of products that are accessible through API’s or Client SDKs (e.g. Datastore, BigQuery, Cloud SQL, …). Those are very easy to include to pom.xml file. (To access any service on google you usually need a service account with JSON configuration file from their Console).

Unfortunately Google didn’t provide very easy interface for Kubernetes to deploy Dockerized images to the cloud so some scripting was needed. I had to create a convenience script to do that for me:

source configuration.sh

This will setup variables that Makefile uses for deployment. Configuration file contains:

  • Project: myproject (can be found after you login to cloud.google.com under Project Info)
  • Cluster: rapido (custom name of the cluster)
  • Machine Type: g1-small (we can also use custom machine type, e.g: custom-2–12288, 2CPUs, 12GB RAM)
  • Disk size: 10 GB
  • Number of Nodes: 1 (number of machines)

To deploy we need to build the Java project, set the right cluster, build a container with Docker, tag the container and push it to Google Registry, then create a deployment descriptor and finally fire the deploy command. All of that is embedded into a single command:

make deployall

If we want to expose the service to the internet:

make expose

It takes some time for external IP to be provided so we can monitor it with:

make ip

In case deployment needs to be updated there is also a command for that:

make update

When we’re done we can delete the environment with:

make deleteall

Conclusion

The hosting part could be easily repurposed for other environments and there is a lot of resources out there how to configure Dockerfile.

I haven’t taken the time to check if it’s maybe easier to deploy Dockerized containers on Azure or maybe AWS. Anyone knows what’s the learning curve to master each of them?