sean-walsh / cloudstate-samples-bookings

An integration sample between cloudstate.io and cadenceworkflow.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A Cloudstate sample application for reserving hotel/flight/car.

Instructions for running locally on a mac with minikube.

  • Clone this repo.
  • clone Cloudstate, git@github.com:cloudstateio/cloudstate.git
  • In your cloned cloudstate master, edit /operator/deploy/02-operator-config.yaml remove -native- from the proxy configuration section, it should like like this:
    
    # Proxy configuration
      proxy {
        image {
          cassandra = "cloudstateio/cloudstate-proxy-cassandra:latest"
          postgres =  "cloudstateio/cloudstate-proxy-postgres:latest"
          no-store = "cloudstateio/cloudstate-proxy-no-store:latest"
          in-memory = "cloudstateio/cloudstate-proxy-in-memory:latest"
        }
      }
    
  • Download and install VirtualBox. note: If using Catalina, the install will fail and you will have to grant the permissions, just follow the prompts, then reinstall.
  • Install homebrew applications:
    
    brew install minikube
    brew install kubectl
    brew install grpcurl
    
  • Start minikube:
    minikube start --vm-driver=virtualbox --cpus 4 --memory 4096
  • Now to build and deploy cloudstate itself, so in the cloudstate folder you cloned, in a terminal window (brew install SBT if necessary): note: you will be using the internally provided docker service within minikube, you don't even have to have Docker Desktop installed and it's probably better to shut it down for this exercise. The command below needs to be executed in each terminal window you will be using.
    eval $(minikube docker-env)
    sbt -Ddocker.tag=dev
    Now from within SBT, assuming you are only using the inmemory store:
    
    operator/docker:publishLocal
    dockerBuildInMemory publishLocal
    operator/compileK8sDescriptors
    
    and exit SBT.
  • Deploy cloudstate:
    
    kubectl create namespace cloudstate
    kubectl apply -n cloudstate -f operator/cloudstate-dev.yaml
    
  • Create a stateful store for inmemory. Save the following in a file, name it statefulstore.yaml
    
    apiVersion: cloudstate.io/v1alpha1
    kind: StatefulStore
    metadata:
      name: inmemory
    spec:
      type: InMemory
    
    Now apply it:
    kubectl apply -f statefulstore.yaml

Whew, now let's install our user functions from this project.

  • In a terminal window, switch into where you cloned this project, then:
eval $(minikube docker-env)
mvn clean install
kubectl apply -f deploy/wirelessmesh.yaml
  • Now this sample is running with cloudstate on your local kubernetes environment. Let's expose a port in order to send GRPC commands and test it out.
kubectl expose deployment bookings-deployment --port=8013 --type=NodePort
  • Issue the following command and record the URL you'll use to interact with your service:
minikube service bookings-deployment --url

Let's assume this resulted in the following:

http://192.168.99.114:32149
  • Some GRPC discovery you can perform, to show the capabilities of this service:

grpcurl -plaintext 192.168.99.114:32149 describe
grpcurl -plaintext 192.168.99.114:32149 list
grpcurl -plaintext 192.168.99.114:32149 list flightservice.FlightBookingService
  • If everything is ok to the point, time to really do something, like reserve a flight:

  grpcurl -d '{"reservationId": "1234", "userId": "sean", "flightNumber": "ua909"}' \
    192.168.99.113:30070 flightservice.FlightBookingService.ReserveFlight
  • And view that reservation:

  grpcurl -plaintext -plaintext -d '{"reservationId": "1234"}' \
  192.168.99.114:32149 flightservice.FlightBookingService.GetFlightReservation

About

An integration sample between cloudstate.io and cadenceworkflow.io

License:Apache License 2.0


Languages

Language:Java 100.0%