Trip Booking Example

This OpenSPARKL configuration organizes a bunch of OpenFaaS functions into an orchestrated “saga”.

“Saga” is the term used to refer to possibly long-running workflows that involve a series of operations on disparate services, with defined rollback or “compensation” actions if something fails.

Before you start

Make sure you’ve installed and started the 3 key dependencies for this demo:

  1. OpenSPARKL including the command-line interface (CLI)

  2. OpenFaaS including the CLI

  3. Docker including Swarm or Kubernetes

The TripBooker Mix

This example mix (pretends to) book a flight, hotel and car for a traveller, making the payment and generating an Ok response if it all works.

If anything fails, it completes “compensation” actions, unbooking what’s been done, and generating an Error response.

  1. Connect to the local SPARKL and login as local admin
    sparkl connect http://localhost:8000
    sparkl login admin@localhost
    
  2. Upload TripBooker.xml which contains the main transactions into the Scratch folder.
    sparkl put http://opensparkl.org/uploads/TripBooker.xml Scratch
    
  3. Upload lib.openfaas.xml into Scratch. This defines the OpenFaaS provision, deprovision and invocation operations for use by TripBooker.xml
    sparkl put http://opensparkl.org/uploads/lib.openfaas.xml Scratch
    
  4. Change to the newly loaded TripBooker folder
    sparkl cd Scratch/TripBooker
    
  5. Execute the Mix/BookTrip transaction, showing a successful response
    sparkl vars -l details "{'fail':'none'}"
    sparkl call Mix/BookTrip
    

    Notice that the OpenFaaS function provisioning of several individual functions happened under the hood. This is what we call reasoned provisioning, because it happens at the moment the business logic needs the provisioned function.

  6. Execute the transaction again, this time showing a failed response due to Car booking failure
    sparkl vars -l details "{'fail':'car'}"
    sparkl call Mix/BookTrip
    
Jacoby Thwaites

Jacoby Thwaites

Strictly no more than 2 cups of coffee, morning only