MLeap Serving (Spring Boot)

This Spring Boot project provides a lightweight docker image for setting up RESTful API services with MLeap models.

Installation

MLeap Spring Boot is a Docker image hosted on Docker Hub.

To get started, pull the image to your local machine, replacing the version with the desired one.

  1. docker pull combustml/mleap-spring-boot:{VERSION}

Start Server

First let’s start the Docker image. Make sure to mount a directory containing your models on the hostmachine into the container. In this example, we will be storing our models in /tmp/models and mounting it in the container at /models.

  1. mkdir /tmp/models
  2. docker run -p 8080:8080 -v /tmp/models:/models combustml/mleap-spring-boot:{VERSION}

This will expose the model server locally on port 8080.

Available Endpoints

  1. POST /models : Loading a model, replacing the name of your bundle zip {BUNDLE_ZIP} and the chosen model name {YOUR_MODEL_NAME}
  1. body='{"modelName":"{YOUR_MODEL_NAME}","uri":"file:/models/{BUNDLE_ZIP}","config":{"memoryTimeout":900000,"diskTimeout":900000},"force":false}'
  2. curl --header "Content-Type: application/json" \
  3. --request POST \
  4. --data "$body" http://localhost:8080/models
  1. DELETE /models/{YOUR_MODEL_NAME} : Unloading a model, replacing the chosen model name {YOUR_MODEL_NAME}
  1. curl --header "Content-Type: application/json" \
  2. --request DELETE \
  3. http://localhost:8080/models/{YOUR_MODEL_NAME}
  1. GET /models/{YOUR_MODEL_NAME} : Retrieving a loaded model, replacing the chosen model name {YOUR_MODEL_NAME}
  1. curl --header "Content-Type: application/json" \
  2. --request GET \
  3. http://localhost:8080/models/{YOUR_MODEL_NAME}
  1. GET /models/{YOUR_MODEL_NAME}/meta : Retrieving a loaded model meta information, replacing the chosen model name {YOUR_MODEL_NAME}
  1. curl --header "Content-Type: application/json" \
  2. --request GET \
  3. http://localhost:8080/models/{YOUR_MODEL_NAME}/meta
  1. POST /models/{YOUR_MODEL_NAME}/transform: Transform or scoring request, replacing the chosen model name {YOUR_MODEL_NAME}, format {YOUR_FORMAT} and the appropriately encoded leap frame {ENCODED_LEAP_FRAME}
  1. body='{"modelName":"{YOUR_MODEL_NAME}","format":"{YOUR_FORMAT}","initTimeout":"35000","tag":0,"frame":"{ENCODED_LEAP_FRAME}"}'
  2. curl --header "Content-Type: application/json" \
  3. --request POST \
  4. --data "$body" http://localhost:8080/models/transform

Format can be either ml.combust.mleap.binary or ml.combust.mleap.json and your leap frame needs to be encoded with that format.

Note: The above endpoints are available either using:

  • JSON (Content-Type header set to application/json)
  • Protobuf (Content-Type header set to application/x-protobuf).

The previous scoring endpoints require you to encode the leap frame, either as JSON or protobuf. If you’d like to try out scoring without having toencode the leap frame, you can use the following endpoint, replacing the chosen model name and your leap frame:

  1. body='{YOUR_LEAP_FRAME_JSON}'
  2. curl --header "Content-Type: application/json" \
  3. --header "timeout: 1000" \
  4. --request POST \
  5. --data "$body" http://localhost:8080/models/{YOUR_MODEL_NAME}/transform

Note: The above endpoint is available either using:

  • JSON (Content-Type header set to application/json) with a JSON leap frame.
  • Protobuf (Content-Type header set to application/x-protobuf) with a protobuf leap frame.

Check out the available Swagger API documentation mleap_serving_1.0.0_swagger.yaml for more information or trying out the API.

Example models:

  1. AirBnB Linear Regression
  2. AirBnB Random Forest

Example leap frames:

  1. AirBnB Leap Frame

See the README.md in mleap-executor project about using gRPC instead of HTTP.